+ Start a Discussion

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?




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

That would result in Too Many SOQL errors.