Friday, March 9, 2018

Salesforce: "No such column 'BOGUS' on entity"

To hopefully save someone the hours I just wasted. If you see this error message when doing an Create, Update, Upsert or Delete using the Force.com PHP Toolkit:
Fatal error: Uncaught SoapFault exception: [sf:INVALID_FIELD] INVALID_FIELD: No such column 'BOGUS' on entity 'Thing__c'.
It's because you've double wrapped the record array:
$createArray = array();
$createArray[0]->Foo__c = 'bar';
$createResult = $sfdcConnection->create(array($createArray), 'Thing__c');
The issue here of course being that the array called "$createArray" is being wrapped in another array... Avoid doing that...

Wednesday, January 31, 2018

Salesforce: Calling batch methods from other batch methods

Have you just had the fun situation where a Salesforce batch has run, which caused something (such as a trigger, etc) to cause another batch to attempt to run?

If you have, then you know the frustration of getting the joyous error message below:


Database.executeBatch cannot be called from a batch or future method.

There are two ways of addressing the "Salesforce Feature". Rewrite your classes to not run if either System.isFuture() or System.isBatch() is true.



or...



Change the API version of all effected classes and triggers to exactly v27.

This single version of the api allows batches to be called from batches. This is obviously not a "good" solution, but if it's a stupid solution, and it works, it's still a solution.