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.

Installer le module soap pour PHP:

$ sudo apt install php-soap

Et redémarrer Apache:

$ sudo service apache2 restart

jrullier@pollux:/var/www$ dpkg -l | grep soap ii php-soap 1:7.0+49 all SOAP module for PHP [default] ii php7.0-soap 7.0.33-0+deb9u7 amd64 SOAP module for PHP ii python3-pysimplesoap 1.16-2 all simple and lightweight SOAP Library (Python 3) jrullier@pollux:/var/www$

 

 

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

Leave a Reply

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Blue Captcha Image
Refresh

*

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.