The toolkit supports the Enterprise and Partner WSDL. You will have access to all the same objects and capabilities of the API from the Partner WSDL as you do from the Enterprise WSDL.


  • PHP 5.x. with cURL, SOAP, and OpenSSL

Tested On (Please add)

  • PHP 5.1.6 on Linux / Apache2.
  • PHP 5.2.0 on Windows.
  • PHP 5.2.1 on Windows.
  • PHP 5.2.2 on Linux / Apache2.
  • PHP 5.2.4 on Linux / Apache2.
  • PHP 5.2.6 on Windows / Apache2.2.8.
  • PHP 5.2.6 on Linux / Apache2.2.8.


In order to use the toolkit, you must ensure that your PHP installation is properly configured. If you will be hosting PHP pages, you will also need to configure your web server appropriately.

Please see PHP Toolkit 11.0 Setup for details.

New developers: Before trying any of the examples you will need to generate a security token by navigating to:

setup->My Personal Information->Reset My Security Token

This will email you a new security token which you must append to your password in the login() API call.

Creating a Connection

In the soapclient directory, you will see the SforceEnterpriseClient and SforcePartnerClient classes which are used to make the connection and all method calls to the API. In order to create a connection, you first instantiate SforceEnterpriseClient or SforcePartnerClient and then pass in the appropriate WSDL. Once you have an instance of SforceEnterpriseClient or SforcePartnerClient, other AppExchange API method calls can be called directly on the instance. In this case, you can login by calling login directly on $mySForceConnection. Browse the API doc to learn more about each available method call.


require_once ('soapclient/SforceEnterpriseClient.php');

$mySforceConnection = new SforceEnterpriseClient();
$mySoapClient = $mySforceConnection->createConnection("enterprise.wsdl.xml");
$mylogin = $mySforceConnection->login("", "changeme");


require_once ('soapclient/SforcePartnerClient.php');

$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection("partner.wsdl.xml");
$mylogin = $mySforceConnection->login("", "changeme");

Results with SObjects


$query = "SELECT Id, FirstName, LastName from Contact";
$response = $mySforceConnection->query($query);

foreach ($response->records as $record) {
  $object = get_object_vars($record);
  echo "Id = ".$object['Id'];
  echo "First Name = ".$object['FirstName'];
  echo "Last Name = ".$object['LastName'];


In the current PHP SOAP extension implementation, you will need to programmatically convert results that return sObjects. Each SObject has a fields array that will contain the fields selected during the query. For example,

$query = "SELECT Id, FirstName, LastName from Contact";
$response = $mySforceConnection->query($query);
// QueryResult object is only for PARTNER client
$queryResult = new QueryResult($response);
foreach ($queryResult->records as $record) {
  echo "Id = ".$record->Id;
  echo "First Name = ".$record->fields->FirstName;
  echo "Last Name = ".$record->fields->LastName;

Note that the Id field is on the sObject and not part of the fields array due to the way that the current SOAP extension handles the Id field. This may change in the future.

SOAP Headers

The API provides SOAP header options to client applications. All of these options are available in both the Enterprise and Partner WSDL files. To use these headers in an PHP client, check out the [samples].

Session Management

When a redirection occurs from one PHP page to another, the SOAP client must be reinstantiated for each page. In the first PHP page after a successful login, store the SessionID, endpoint, and WSDL reference in the session:

$_SESSION['location'] = $mySforceConnection->getLocation();
$_SESSION['sessionId'] = $mySforceConnection->getSessionId();
$_SESSION['wsdl'] = $wsdl;

header('Location: welcome.php');

On the second PHP page, reinstantiate the SOAP client by reusing the attributes that were stored in the session:

// Retrieve session attributes
$location = $_SESSION['location'];
$sessionId = $_SESSION['sessionId'];
$wsdl = $_SESSION['wsdl'];

$mySforceConnection = new SforcePartnerClient();
$sforceSoapClient = $mySforceConnection->createConnection($wsdl);