php salesforce novice INVALID_FIELD: No such column 'fields' on entity 'Contact' ← (PHP)

Solution:

Looking at your trace you appear to be using the enterprise client and I can assume enterprise WSDL. This is strongly typed and you should be using the WSDL specific to your Salesforce org. If you are not using the WSDL downloaded from your org it will not have the correct objects and fields defined within it.

I would recommend using the partner client and partner WSDL. This is loosely typed and far more flexible. It would be easier to work with particularly if you aren't familiar with the PHP or the webservices.

The following should do your update...

$sObject1 = new stdClass();
$sObject1->type = 'Contact';
$sObject1->Id = $id;
$sObject1->fields['MailingCity'] = 'New York';
$sObject1->fields['MailingState'] = 'NY';

try
{
    $updateResponse = $client->update( array( $sObject1 ) );
}
catch( Exception $exception )
{
    // Do something
}

Note that the Id is a property of $sObject and not a value in the fields array. Also there is no need to specify the 'Contact' in your update call as you have it set in the type property of $sObject.

Answer



Solution:

When using the Enterprise WSDL, don't create a new SObject, just create a new stdClass. See the examples in the PHP Getting Started Guide; SObjects are only for use with the partner WSDL.

Answer



Solution:

I have encountered the same issue updating while using the Enterprise client. I experienced the same issue while updating a custom field on an Account object.

The issue that I had with the SObject was that it tried to update a parameter called 'fields' during the update. With the Enterprise WSDL not including that field, I used unset() to remove the 'fields' attribute from the SObject.

I appreciate this is a bit of a hacky solution, but it could come in useful for others that encounter this issue.

$sUpdateObject = new SObject();
$sUpdateObject->id = $record->Id;
$sUpdateObject->MyCustomField__c = 0;
unset($sUpdateObject->fields);

$updateResponse = $mySforceConnection->update(array($sUpdateObject), 'Account');
print_r($upsertResponse);

Source