function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Marcio FritschMarcio Fritsch 

RecalculateFormulas method does not work with Master-Detail field picked.

Recently I have tested ApexPages.StandardSetController method and used .save method and worked fine. However I have changed to add new Calculated fields and tried to use .RecalculateFormulas() available for sobject and I faced a message error:
Unable to create/update fields: <sobject>. Please check the security settings of this field and verify that it is read/write for your profile or permission set.
I think there is nothing regarding to this above once I just took out the .save() method and just invoked the recalculateFormulas(). If I just take out the master_detail_field from my query, it works.
Code sample below:
...
ApexPages.StandardSetController([SELECT id, name, Master_detail_Field__c FROM sobject])
...
        for(sobject s: setRecords.getrecords()){
            s.recalculateFormulas();
        }
pconpcon
Does your current user have access to the Master_detail_Field__c and it's object (both object level and FLS on the child object)?
Marcio FritschMarcio Fritsch
Yes it does, it is System Administrator having same object level permissions. I imagine that it is an Issue from recalculateFormulas not sure yet.
Sebastian SchwarzSebastian Schwarz

Seems like it is related to this Known Issue: https://success.salesforce.com/issues_view?id=a1p300000008bvw

if so, check the "Affects me" check box :)

"This issue happens if there are fields which are not updatable in SOQL" (src: StackExchange (http://salesforce.stackexchange.com/questions/100627/winter-16-recalculateformulas-fails-when-sobject-has-relationship-fields))