Source: http://www.jitendrazaa.com/blog/salesforce/salesforce-toolkit-for-php/

Author posted by Jitendra on Posted on June 7, 2012 under category Categories Force.com, Salesforce, Web Technology and tagged as Tags PHP, Salesforce with 14 Comments

Example of using PHP toolkit in Salesforce with Sample code

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.
[sourcecode language=’css’]

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 ‘
‘.$record->Id.’

‘.$record->fields->FirstName.’

‘.$record->fields->LastName.’

‘.$record->fields->Phone.’

‘;
}
[/sourcecode]
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:

Print Friendly, PDF & Email

Laissez un commentaire

You have to agree to the comment policy.

Vous pouvez utiliser ces tags et attributs HTML:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>