Using the new method on sObject recalculateFormulas()
fails when the Sobject includes relationship fields - note account.name
in the query.
FATAL_ERROR System.UnexpectedException: Opportunity: bad field names on insert/update call: Account
Opportunity[] oList = Database.query('select id, account.name, amount from Opportunity limit 1');
for (Opportunity o : oList)
o.recalculateFormulas();
If I try using inline SOQL; same error
Opportunity[] oList = [select id, account.name, amount from Opportunity limit 1];
for (Opportunity o : oList)
o.recalculateFormulas();
and it fails when using child relationships as well:
FATAL_ERROR System.UnexpectedException: Opportunity: bad field names on insert/update call: OpportunityLineItems
Opportunity[] oList = [select id, (select id from OpportunityLineItems), amount from Opportunity limit 1];
for (Opportunity o : oList)
o.recalculateFormulas();
Looks like a bug to me as otherwise if restricted to only 'pure' sObjects, code will break as soon as SOQL statements are extended with innocuous relationship fields. Unless someone knows otherwise, bug report will be filed to SFDC Support
UPDATE ...a few days later
Curiously, relationship names in a query for Contact do not generate the error
Contact[] cList = [select id , account.name from Contact limit 10] ;
for (Contact c: cList)
c.recalculateFormulas();
nor is there an error with relationship names on a Case query
Case[] csList = [select id , account.name from Case limit 10] ;
for (Case cs: csList)
cs.recalculateFormulas();
or (also works fine)
Case[] csList = [select id , (select id from CaseComments) from Case limit 10] ;
for (Case cs: csList)
cs.recalculateFormulas();
BUT .. relationship names on Custom Objects fail as they did on the Opportunity example:
Quote__c[] qList = [select id, opportunity__r.amount from Quote__c limit 10];
for (Quote__c q : qList)
q.recalculateFormulas();
SFDC Support says this support ticket is "interesting"
Update 2015-12-04 - Per SFDC T3 Support: "This seems to be progressing in the direction of getting identified as a bug"