When trying to generate a soap access token for salsforce I am getting an error:

Fatal error: Call to a member function __setSoapHeaders() on a non-object in D:\XAMPP\htdocs\test24\soapclient\SforceBaseClient.php on line 158

I'm not sure how to solve this.


     require ('config.php');
     ini_set('soap.wsdl_cache_enabled', 0);
     ini_set('soap.wsdl_cache_ttl', 0);

     //Create a new Salesforce Partner object
     $connection = new SforcePartnerClient();

 //Create the SOAP connection to Salesforce
 try {
 } catch (Exception $e) {
    //Salesforce could be down, or you have an error in configuration
  //Check your WSDL path
  //Otherwise, handle this exception

 //Pass login details to Salesforce
 try {
  $connection->login(salesforce_username, salesforce_password.salesforce_token);
 } catch (Exception $e) {
  //Make sure your username and password is correct
  //Otherwise, handle this exception

 //Describing the Leads object and printing the array
     $describe = $connection->describeSObjects(array('Lead'));

     //Create New Lead
     $leadFirstName = "Ahmed";
     $leadLastName = "Dirie";
     $leadCompany = "Pick Yours Up";
     $leadEmail = "adirie@pickyoursup.com";

     //Creating the Lead Object
     $lead = new stdClass;
     $lead->type = 'Lead';
     $lead->fields = array(
          'FirstName' => $leadFirstName,
          'LastName' => $leadLastName,
          'Company' => $leadCompany,
          'Email' => $leadEmail

     //Submitting the Lead to Salesforce
     $result = $connection->create(array($lead), 'Lead');
  • 1
    Please provide your full code. Where does your $connection variable come from? – Martin Lezer Feb 24 '16 at 8:28
  • Is this using the php-toolkit by salesforce ? – Samuel De Rycke Feb 24 '16 at 8:43
  • yes. i am using soapclient library of php-toolkit with this code. And by this code i am defining my credentials <?php define ("salesforce_username", 'YOUR_USERNAME'); define ("salesforce_password", 'YOUR_PASSWORD'); define ("salesforce_token", 'YOUR_TOKEN'); define ("salesforce_wsdl", 'soapclient/partner2.wsdl.xml'); require_once ('soapclient/SforcePartnerClient.php'); ?> – Priyanka Gurav Feb 24 '16 at 8:57

If you open the file soapclient\SforceBaseClient.php and go to line # 158 you will realalize that it is setting the headers there.

the code there will be something like.


What it is doing is its setting header using $this->sforce and by looking at error it seems like $this->sforce is non-object.

When we back trace, we find its setting the value of $this->sforce in createConnection() function in SforceBaseClient.php

I would suggest you to place echo and var dump to see when its setting that object and when its getting reset to null.

If its confusing for you then you can try and use different (older or newer) version of this toolkit. Generally this work just fine.

  • Thanks for your response @AtulRajguru9. I tried echo on $this->sforce, but it is not showing anything. When i tried downloading older version of toolkit like PHP toolkit 13.1. Link is redirecting me to this url developer.salesforce.com. – Priyanka Gurav Feb 24 '16 at 10:18
  • Can you put debug statement in createConnection and see if $this->sforce is initialized properly ? – AtulRajguru9 Feb 24 '16 at 11:45
  • Can you please tell me steps or code example to generate token and passing values to the salesforce api in php. Because i am not aware, am i going right or not. Thanks in advance. – Priyanka Gurav Feb 25 '16 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.