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
TheReportDoctorTheReportDoctor 

When are formula fields calculated?

I have a calculated field.  When I set values in the record via a class and then I look to the formula field it is null.  Is there a way I can say do the calc now?

 

TRD

imuinoimuino

From apex code documentation:

 

Also note that sObject fields that contain formulas return the value of the field at the time the SOQL or SOSL query was issued.

 

You may need to query the result of the insert to calculate the formula

TheReportDoctorTheReportDoctor
That would result in Too Many SOQL errors.