[SalesForce] Event execution order

In which order does Salesforce execute events upon saving a record?

  1. Before Triggers; Validation Rules; After Triggers; Assignment Rules; Workflow Rules; Commit

OR

  1. Validation Rules; Before Triggers; After Triggers; Assignment Rules; Workflow Rules; Commit

As per the order of execution of salesforce events, standard validation rules are executed, followed by Before Triggers and then custom validation rules, so I am not sure which one among these is correct.

Best Answer

There is a distinction between standard validation rules (number fields must be numbers, etc) and custom validation rules (discount > 20)

Triggers need to have valid sobjects passed to them, hence data scrubbing is done by SFDC prior to before trigger execution. Since before triggers can modify the sobject, the custom validation rules need to execute after the before trigger has completed.

Related Topic