Winter 16 recalculateFormulas() fails when sObject has relationship fields
SFDC R&D has confirmed a bug in recalculateFormulas
method . As of 0900h Pacific 2015-12-09, Known Issue
not yet created.
From Support:
For now as a work around we would request you not select any lookup fields in the SOQL query when using the recalculateFormulas()
From R&D:
This issue happens if there are fields which are not updatable in SOQL.For example, if there are the fields which refer to the other object's field like account.name, it is not directly updatable, so it causes the error.If you specify the lookup field itself like accountId, it is updatable, it is OK, but if the field is not updatable like master-detail field, auto-populated lookup field, it causes the error.Some reason, if the lookup field doesn't have value like accountId = null, this error doesn't happen even if the field account.name is in SOQL.Auto number field causes the same issue because it is not updatable.
The workaround is do not put this kind of fields (not updatable) in SOQL.
This workaround, as obvious as it sounds, is not always going to be practical as one's SObject fetched from SOQL frequently has lookup fields or child relationships. Even worse, perfectly working code could break in difficult to understand ways if in the future, one innocuously adds lookup fields or relationship fields to the SOQL (say, to get the Opportunity Owner Name to display on a VF page)
I'll post updates if and when I get a scheduled fix date or release.
Here is the Known Issue prompted by the above. The more folks mark this as "it affects me", the more likely it will be the issue is fixed.