Salesforce Toolkit for PHP

Author posted by Jitendra on Posted on under category Categories, Salesforce, Web Technology and tagged as Tags , with 24 Comments on Salesforce Toolkit for PHP

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 –

In a toolkit downloaded, only important folder is “soapclient“. Copy that folder in your project directory. The 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->login(USERNAME, PASSWORD.SECURITY_TOKEN);

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

foreach ($response->records as $record)
echo '<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: toolkit for PHP toolkit toolkit for PHP toolkit

Download Salesforce PHP Toolkit Example – Zip

You can refer this article also on developerforce.

Related posts

24 thoughts on “Salesforce Toolkit for PHP”

  1. Hi there. I am pretty green at developing php apps but I want to take a shot at this.. I have a slightly different requirement though and i was wondering if you could help me through it. I am trying to check to see if a specific record is a client based on a field in salesforce. This post gets me part the way there but I need to be able to tell based on email comparison whether or not :

    1. The email exists in sales force…
    2. And for that record see if the field customer is a “yes” or “blank”
    3. if yes respond yes if blank respond no

    is this possible?

  2. Hi, How to upsert picklist values into salesforce via PHP integration?? picklist is order status field?


  3. HI, I can’t seem to make the connection right. I am having a Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host. Any advice how to solve this?



  4. Hi,

    I am new to PHP. Can any one help me to install all this software’s in windows environment.(“PHP 5.x with the cURL, SOAP and OpenSSL”) that is required for the tool kit

  5. Hi Jitendra,

    The XAMPP worked fine for me.I have a small doubt.I am having the PHP form where the user fill all the details and click submit

    How should i pass the values (Filled in the form )dynamically to create a record in salesforce

    Suppose, I have First Name and Last name In My from and user submits .How to capture the values and create the record in salesforce.


    1. Hi Praveen,

      My scenario was something near to your post. As i am waiting for help from anyone.

      My task is like i have to integrate salesforce with external website. The developer at the external end will push data in PHP script format.
      Then how do i get those data into salesforce and save. Do i need to code to get that..
      Any suggestions will be helpful..!

      1. Hi Anshul,

        If you have a php developer trying top push the data from the external website .you need to give him the credentials to authenticate and save the data on salesforce.

        Steps to follow:

        1) please create an connected App in your salesforce
        Setup->create->apps ->Connected App (Through which you will get the Client_ID and client _Secret )

        “grant_type” => “password”,
        “client_id” => “GET FROM Connected APP”,

        “client_secret” => “GET FROM Connected APP”,

        “username”==> “salesforce username(maybe an API user used for integration or our username “,

        “password” => “Salesforce password”,

        “security_token”=> “salesforce security token fro the user”,

        If you give this values to the php developer he will be able to use the credentials and try to push the data to salesforce.


        1. Thank alot Praveen.

          So, as you said, There is no need for me to code anything, Instead i have to pass the credentials to the PHP Developer.
          Once he pushes the data into salesforce will i be able to use it directly.


  6. Nice tutorial,
    Does API limit gets counted?
    How many records we can insert/update in one transaction using this toolkit ?

  7. Hello Sir, Thank you for your post its works well. I have some requirement if I add custom fields say coordinate in Account object. How I can retrieve it ??. I used API name(Coordinates__c) same as under Account Custom Fields & Relationships but its not working. Can you please help me?

  8. Hello
    I have free trial account in
    but i am not able to download
    PartnerWSDL.xml file
    and where i can got SECURITY_TOKEN Please help me regarding this

  9. foreach ($response->records as $record) {
    echo “”;

    The above works but I am not able to grab the individual fields using:

  10. how to delete record from salesforce in php
    here is my code but not working
    require_once (‘soapclient/SforcePartnerClient.php’);

    $mySforceConnection = new SforcePartnerClient();
    $mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);
    $ids[0] = new stdclass();
    array_push($ids, $id);
    $deleteResult = $mySforceConnection->delete($ids);

  11. Hi,
    It says

    PHP Fatal error: Class ‘SoapClient’ not found in /var/www/html/psgff/api/soapclient/SforcePartnerClient.php on line 44,

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.