Receiving Error when querying for lookup fields while using sObject.recalculateFormulas() method.
Apex , API , VisualForce , Eclipse IDE , Developer Console , Winter 16
Last updated Today ·Reference W-2861176 ·Reported By 243 users
In Review
Summary
Exception occurs when sObject.recalculateFormulas() is called and the query which retrieves the object may or may not contain reference fields.
Example error:
FATAL_ERROR System.UnexpectedException: Opportunity: bad field names on insert/update call: Account
NOTE : If the fields are not updatable and they are in SOQL, it causes the error. Some special fields like IsPersonAccount for Account, IsClosed for Case on the standard objects are also not updatable, so it should cause the same issue as well.
Repro
1) Add a formula field on Case
2) Create an account record
3) Create a case record which has reference to 2)
4) Open developer console and invoke the apex code below from the Execute Anonymous Window
Case c = [select id , account.name from Case WHERE id='500xx000000Yl1I'];
c.recalculateFormulas();
or
Case c = [select id from Case WHERE id='500xx000000Yl1I'];
Formula.recalculateFormulas(c);
Workaround
Use Formula.reclaculateFormulas() API
Previous workaround:
==========
Avoid retrieving lookup fields in SOQL queries that retrieves the target sObjects.
Reported By (243)



































































Is it Fixed?
Any unreleased services, features, statuses, or dates referenced in this or other public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make their purchase decisions based upon features that are currently available.