Salesforce Toolkit for PHP

Get articles everyday as a email directly to your inbox:
Click to publicize, if you like this article :

In a web development PHP has prooved itself as one of the major contributor in the world. There are lots of websites which are built over the PHP and the best example is facebook. PHP is very powerfull, easy to learn and the best thing is that it is open source.

Following the popularity of PHP, salesforce has also started providing support to PHP and delivered the Toolkit for it. Using this toolkit we can connect with salesforce and perform all API operations supported like Insert, update, delete, retrieve etc.

Download Salesforce PHP Toolkit Example – Zip

We can download the toolkit from this URL – Gits - https://github.com/developerforce/Force.com-Toolkit-for-PHP

In a toolkit downloaded, only important folder is “soapclient“. Copy that folder in your project directory. The Force.com PHP Toolkit requires PHP 5.x with the cURL, SOAP and OpenSSL PHP modules.

Next step is to download “Partner WSDL” from Salesforce (we have already seen the example of  Enterprise WSDL so this time i am using Partner WSDL). To download Partner WSDL, Click Your Name | Setup | Develop | API to display the WSDL download page. Download the Partner WSDL and save as “PartnerWSDL.xml”.

Add below code snippet in your PHP page to retrieve the information from Salesforce using toolkit.

define("USERNAME", "Your salesforce username");
define("PASSWORD", "salesforce password");
define("SECURITY_TOKEN", "salesforce security token");

require_once ('soapclient/SforcePartnerClient.php');

$mySforceConnection = new SforcePartnerClient();
$mySforceConnection->createConnection("PartnerWSDL.xml");
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);

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

foreach ($response->records as $record)
{
echo '<tr>
	<td>'.$record->Id.'</td>
	<td>'.$record->fields->FirstName.'</td>
	<td>'.$record->fields->LastName.'</td>
	<td>'.$record->fields->Phone.'</td>
	 </tr>';
 }

As you can see in above code, we have imported the php file “SforcePartnerClient.php” which is provided by tookit. Add the UserName, Password and Security token in above code. To access the field from Object use syntax “recordset->fields->FieldName”.
The final output of the example attached in this article would look like:

force.com toolkit for PHP toolkit

force.com toolkit for PHP toolkit

Download Salesforce PHP Toolkit Example – Zip

You can refer this article also on developerforce.

You can leave a response, or trackback from your own site.
  • Shiva

    This is ok.But Can you retrieve any document from Salesforce using php?