Contents

Overview

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.

Requirements

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

Tested On (Please add)

  • PHP 5.3.2 on Linux / Apache2.
  • 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.3.0 on Windows.

Setup

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.

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.

Enterprise

require_once ('soapclient/SforceEnterpriseClient.php');

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

Partner

require_once ('soapclient/SforcePartnerClient.php');

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

Results with SObjects

Enterprise

TK

Partner

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->FirstName;
  echo "Last Name = ".$record->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 Force.com 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_start();
$_SESSION['location'] = $mySforceConnection->getLocation();
$_SESSION['sessionId'] = $mySforceConnection->getSessionId();
$_SESSION['wsdl'] = $wsdl;

session_write_close();
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
session_start();
$location = $_SESSION['location'];
$sessionId = $_SESSION['sessionId'];
$wsdl = $_SESSION['wsdl'];

$mySforceConnection = new SforcePartnerClient();
$sforceSoapClient = $mySforceConnection->createConnection($wsdl);
$mySforceConnection->setEndpoint($location);
$mySforceConnection->setSessionHeader($sessionId);