Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Salesforce by (11.9k points)

I am using the below code to connect to salesforce using PHP

require_once ('SforcePartnerClient.php');

require_once ('SforceHeaderOptions.php');  

require_once ('SforceMetadataClient.php'); 

$mySforceConnection = new SforcePartnerClient(); 


$loginResult = $mySforceConnection->login("username", "password.token");

$queryOptions = new QueryOptions(200);

try {

  $sObject = new stdclass();

  $sObject->Name = 'Smith';

  $sObject->Phone = '510-555-5555';

  $sObject->fieldsToNull = NULL;

  echo "**** Creating the following:\r\n";

  $createResponse = $mySforceConnection->create($sObject, 'Account');

  $ids = array();

  foreach ($createResponse as $createResult) {


    array_push($ids, $createResult->id);


} catch (Exception $e) {

  echo $e->faultstring;


But the above code is connected to salesforce database. But is not executing the create commands. it's giving me the below error message

Creating the following: Element {}item invalid at this location

can anyone suggest me to overcome the above problem

1 Answer

0 votes
by (32.1k points)
edited by

MAK, in your sample code SessionHeader and Endpoint setup calls are missing



after setting up those, if you still see an issue, check the namespace urn


It should match targetNamespace value in your WSDL.

Want to get certified in Salesforce? Here is the Salesforce Online Training you are looking for!

Browse Categories