Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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(); 

$mySforceConnection->createConnection("cniRegistration.wsdl");

$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) {

    print_r($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)

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

$mySforceConnection->setEndpoint($location);

$mySforceConnection->setSessionHeader($sessionId);

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

$mySforceConnection->getNamespace

It should match targetNamespace value in your WSDL.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...