function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ssuede7ssuede7 

simple PHP contact update not working

Hi,

 

I am fairly new using PHP with Salesforce, I have successfully created several query calls and gotten results back, but now I want to update a contact but the code is failing.  I have compared my code to several examples and can find no problems, but it still doesn't work.  Here is the code:

 

 

$mySforceConnection = new SforceEnterpriseClient(); $mySoapClient = $mySforceConnection->createConnection($wsdl); $mylogin = $mySforceConnection->login($username, $password); $sObject1->fields = array('FirstName' => 'Josh'); $sObject1->type = 'Contact'; $sObject1->Id = '00330000004dBxw'; $response = $mySforceConnection->update(array($sObject1));

 

 

The error message I get is this:

 

PHP Warning:  Missing argument 2 for SforceEnterpriseClient::update(), called in C:\inetpub\wwwroot\account.php on line 21 and defined in C:\inetpub\wwwroot\system\soapclient\SforceEnterpriseClient.php on line 68
PHP Notice:  Undefined variable: type in C:\inetpub\wwwroot\system\soapclient\SforceEnterpriseClient.php on line 70
PHP Fatal error:  Uncaught SoapFault exception: [sf:INVALID_TYPE] INVALID_TYPE: Must send a concrete entity type. in C:\inetpub\wwwroot\system\soapclient\SforceBaseClient.php:414
Stack trace:
#0 [internal function]: SoapClient->__call('update', Array)
#1 C:\inetpub\wwwroot\system\soapclient\SforceBaseClient.php(414): SoapClient->update(Object(stdClass))
#2 C:\inetpub\wwwroot\system\soapclient\SforceEnterpriseClient.php(73): SforceBaseClient->_update(Object(stdClass))
#3 C:\inetpub\wwwroot\account.php(21): SforceEnterpriseClient->update(Array)
#4 {main}
  thrown in C:\inetpub\wwwroot\system\soapclient\SforceBaseClient.php on line 414

 

As you can see I've made the code pretty simple to eliminate possible problem points.  The core error seems to be "INVALID_TYPE: Must send a concrete entity type"  Anyone have any ideas?

 

I am using PHP 5.3.0 with the PHP 13.0 Toolkit.

Best Answer chosen by Admin (Salesforce Developers) 
Park Walker (TAGL)Park Walker (TAGL)

The example that your code is based on is for the Partner WSDL, but your code is using the Enterprise WSDL. The two use different object composition methods. In the Partner WSDL, the Id, type and fields array are used. In the Enterprise the actual object is used, with direct access to the fields (e.g. $acct->Name). The Enterprise model requires a second parameter on the create cal to identify the type of the object since there is no type field. That's the error that you are receiving, but simply passing the object type will not solve your problem. You either need to use the Partner WSDL or change your code to be compatible with the Enterprise WSDL.

 

Park 

All Answers

Park Walker (TAGL)Park Walker (TAGL)

The example that your code is based on is for the Partner WSDL, but your code is using the Enterprise WSDL. The two use different object composition methods. In the Partner WSDL, the Id, type and fields array are used. In the Enterprise the actual object is used, with direct access to the fields (e.g. $acct->Name). The Enterprise model requires a second parameter on the create cal to identify the type of the object since there is no type field. That's the error that you are receiving, but simply passing the object type will not solve your problem. You either need to use the Partner WSDL or change your code to be compatible with the Enterprise WSDL.

 

Park 

This was selected as the best answer
ssuede7ssuede7

Thanks Park! 

 

I changed my code to:

 

$sObject1 = new stdClass(); $sObject1->FirstName = 'Josh'; $sObject1->Id = '00330000004dBxwAAE'; $response = $mySforceConnection->update(array($sObject1), 'Contact');

 

And it is now working. 

 

There is no example in the PHP13.0 enterprise code samples for how to do this and the posts I was referrencing were all partner examples it seems.

 

Josh