Salesforce Toolkit for PHP

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


29 responses to “Salesforce Toolkit for PHP”

  1. Shiva Avatar

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

  2. CIS Avatar


    i have copied the SFDC kit on root and tried but it’s not working.

  3. Chad Pierce Avatar

    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?

  4. Richa Upadhyay Avatar
    Richa Upadhyay

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


  5. Benessa Mae Dumol Avatar

    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?



    1. Jitendra Zaa Avatar

      DO you have debug enabled in your PHP server and any idea on which page and line ? Issue might be in configuration.

  6. Praveen Kumar Avatar
    Praveen Kumar


    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

    1. Jitendra Zaa Avatar

      You can use XAMPP installer which contains everything. This post might be useful –

      1. Praveen Kumar Avatar
        Praveen Kumar

        Thank you jitendra.

  7. Praveen Kumar Avatar
    Praveen Kumar

    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. Anshul.sf Avatar

      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. Praveen Kumar Avatar
        Praveen Kumar

        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. Anshul.sf Avatar

          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.


  8. Shubham Sharma Avatar
    Shubham Sharma

    SELECT Id, FirstName, LastName, Phone from Contact Where is contact table

  9. […] special note of thanks to Jitendra Zaa – it was this post from 4 years ago which prompted me to take up this task of revamping the PHP […]

  10. Arul ECE Avatar
    Arul ECE

    Hi I need help can any one help me my email id is

  11. sndeep Avatar

    thanks a lot it worked for me

  12. Nilesh Borse Avatar
    Nilesh Borse

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

  13. niharika22indiaNiharika Avatar

    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?

  14. vinod kumar Avatar
    vinod kumar

    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

  15. Samantha Avatar

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

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

  16. vineet shirdhonkar Avatar
    vineet shirdhonkar

    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);

  17. Jasbir singh rana Avatar
    Jasbir singh rana

    It says

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

  18. guy peled Avatar
    guy peled

    Do you have an example of how to update a record:

  19. Simon Webb Avatar
    Simon Webb

    Hi all, does anybody know how to create an Opportunity, this is driving me mad, many thanks if you can help me.

  20. Leo Nuneza Avatar
    Leo Nuneza

    Did you encounter “Login Rate Exceeded” for api call. How to fix it

  21. UK Avatar

    Experts good afternoon!!
    We use custom domain for salesforce login. Eg. ab Where do pass the custom domain url in PHP tool kit? I m receiving access denied error because of lack of this custom domain URL. Appreciate your input and advise.

    1. Ansari Avatar

      The login URL is part of wsdl. Make sure to use “PASSWORD.SECURITY_TOKEN”

  22. vic palma Avatar
    vic palma

    works with standard object but with customs object i got error

Leave a Reply

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

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading