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
thunksalotthunksalot 

Which gets evaluated first on save, Validation Rules or Formula fields?

I would like to create a validation rule that fires if a formula field on our Opportunities has a certain value.  I already have the formula field, which is useful for other things besides this validation function.  So, I'd like it if I could just write a validation rule that checks the value of the formula field, but I'm not sure if it is *always* the case that on save the formula field would get updated *before* the validation rule runs. 

 

I realize I can copy the part of the formula field's logic that is relevant to the validation rule into the validation rule's formula, but if I can avoid duplicating logic that then has to be maintained separately, I'd like to do that.

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,

 

I think validation rule will run first before update the formula field value. Standard Salesforce.com order of execution

  • Old record loaded from database (or initialized for new inserts)
  • New record values overwrite old values
  • System Validation Rules
  •  All Apex “before” triggers
  •  Custom Validation Rules
  •  Record saved to database (but not committed)
  •  Record reloaded from database
  • All Apex “after” triggers
  • Assignment rules
  • Auto-response rules
  • Workflow rules
  • Escalation rules
  •  Parent Rollup Summary Formula value updated (if present)
  •  Database commit
  •  Post-commit logic (sending email)

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

 

I think validation rule will run first before update the formula field value. Standard Salesforce.com order of execution

  • Old record loaded from database (or initialized for new inserts)
  • New record values overwrite old values
  • System Validation Rules
  •  All Apex “before” triggers
  •  Custom Validation Rules
  •  Record saved to database (but not committed)
  •  Record reloaded from database
  • All Apex “after” triggers
  • Assignment rules
  • Auto-response rules
  • Workflow rules
  • Escalation rules
  •  Parent Rollup Summary Formula value updated (if present)
  •  Database commit
  •  Post-commit logic (sending email)

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

This was selected as the best answer
thunksalotthunksalot

That completely answered my question, thank you.  I tried to find a list like that but couldn't.  Thanks to you, I was able to find a place where it is published by SF.  If anything changes, perhaps they will keep the list in this KB article updated:  https://help.salesforce.com/apex/HTViewSolution?id=000005694&language=en_US