Can anyone tell me exactly when the calculation of formula field happens?



2 Answers 2


It's calculated on demand, and thus does not participate in the order of execution. In practice, that means it calculated each time it is queried from the database.

In the context of a DML operation, each formula is recalculated while loading Trigger.old and Trigger.new, before evaluating validation, assignment, escalation, and workflow rules, and while executing process builder, flow, and approval processes.

You can also request a reevaluation in Apex Code using recalculateFormulas.

  • 2
    recalculateFormulas - some gotchas - see salesforce.stackexchange.com/questions/100627/…
    – cropredy
    Feb 3, 2016 at 22:44
  • @crop1645 There's always some caveats, it seems like, the main point was to say that the data comes "on demand" as opposed to being calculated and stored at any specific point during a transaction.
    – sfdcfox
    Feb 3, 2016 at 22:54
  • no worries, I was just trying to help some future reader from wasting as much time as I did on recalcualteFormulas
    – cropredy
    Feb 3, 2016 at 22:56
  • how does formula field perform for reports ? It gets calculated on-demand ? @sfdcfox Jul 23, 2021 at 19:25
  • 1
    @ChiragVerma As a selected field to return, they are very performant. As a filter on a report, they can cause a "full table scan" without other filters, and may therefore slow down reports where there are millions of potential matches (e.g. an object with millions of records, and most users can see most/all of those records by way of sharing or profile permissions).
    – sfdcfox
    Jul 23, 2021 at 19:39

Hopefully this Knowledge article helps.

In what order are automation rules and Apex triggers processed? Knowledge Article Number 000005694

Description In what order are automation rules and Apex triggers processed?

Resolution The following is the order salesforce logic is applied to a record. Old record loaded from database (or initialized for new inserts) New record values overwrite old values System Validation Rules (If inserting Opportunity Products, Custom Validation Rules will also fire in addition to System Validation Rules) All Apex before triggers (EE / UE only) Custom Validation Rules Record saved to database (but not committed) Record reloaded from database All Apex after triggers (EE / UE only) Assignment rules Auto-response rules Workflow rules Processes Escalation rules Parent Rollup Summary Formula value updated (if present) Database commit Post-commit logic (sending email) Additional notes: There is no way to control the order of execution within each group above. Workflow field updates that run based on an approval process or time-dependent action do not trigger any rules. Formula fields do not execute in this way. They calculate and display their results real-time whenever the field is accessed in any way. So for example if a Workflow Rule uses a Formula Field in its criteria or formula, the formula field is evaluated when the Workflow Rule criteria is checked.

For additional details on the Order of Execution please review: https://help.salesforce.com/s/articleView?id=000327325&type=1

  • Kristin - you might want to reformat the answer, the line breaks were lost :-)
    – cropredy
    Feb 3, 2016 at 22:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .