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
Nicolas DupuisNicolas Dupuis 

recalculateformulas error

Hi all,

I am trying to do a mass update of formulas on Opportunity Line Items. I wanted to use recalculateformulas() but got an error.

Here is my script:
List<OpportunityLineItem> opportunitylineitems = [select id from OpportunityLineItem where PricebookEntry.Pricebook2Id = '01s20000000UD8hAAG'];
for (OpportunityLineItem oli : opportunitylineitems) (
oli.recalculateFormulas());

And here is the the error message:

Line: 3, Column: 1
System.UnexpectedException: Unable to create/update fields: CurrencyIsoCode, PricebookEntryId. Please check the security settings of this field and verify that it is read/write for your profile or permission set.

Any help would be appreciated.

Thanks
Geoffrey BessereauGeoffrey Bessereau
Seems like another automation is trying to update CurrencyIsoCode and PricebookEntryId on your opportunity line items.

Check your debug logs to see if/why that other automation triggers.
Nicolas DupuisNicolas Dupuis
Thanks for your answer.
 
I could not find anything, here are the logs if you can spot a problem:
 
13:29:30.1 (2676694)|SOQL_EXECUTE_BEGIN|[1]|Aggregations:0|SELECT id FROM OpportunityLineItem WHERE PricebookEntry.Pricebook2Id = '01s20000000UD8hAAG'
13:29:31.257 (1257525338)|SOQL_EXECUTE_END|[1]|Rows:14060
13:29:31.257 (1257668557)|HEAP_ALLOCATE|[1]|Bytes:56244
13:29:31.257 (1274840122)|HEAP_ALLOCATE|[1]|Bytes:1251340
13:29:31.257 (1274907476)|HEAP_ALLOCATE|[1]|Bytes:56244
13:29:31.257 (1274971617)|VARIABLE_ASSIGNMENT|[1]|opportunitylineitems|"List of size 14060 too large to display"|0x69185190
13:29:31.257 (1275262581)|HEAP_ALLOCATE|[2]|Bytes:5
13:29:31.257 (1275322432)|HEAP_ALLOCATE|[2]|Bytes:16
13:29:31.257 (1275338277)|VARIABLE_SCOPE_BEGIN|[2]|oli|OpportunityLineItem|true|false
13:29:31.257 (1275369238)|VARIABLE_ASSIGNMENT|[2]|oli|{"Id":"00kw000000ap8VVAAY","PricebookEntryId":"01uw000000pXfuAAAS","CurrencyIsoCode":"EUR"}|0x102514d7
13:29:31.257 (1275378474)|STATEMENT_EXECUTE|[3]
13:29:31.257 (1434627908)|EXCEPTION_THROWN|[3]|System.UnexpectedException: Unable to create/update fields: CurrencyIsoCode, PricebookEntryId. Please check the security settings of this field and verify that it is read/write for your profile or permission set.
 
Thanks