When a record is saved with an insert, update, or upsert statement, the following events occur in order:
- The original record is loaded from the database or initialized for in case of an insert statement.
- The new record field values are loaded from the request and overwrite the old values.
- System validation occurs, such as verifying that all required fields have a non-null value, and running any user-defined validation rules.
- All before triggers execute.
- The record is saved to the database, but not yet committed.
- All after triggers execute.
- Assignment rules execute.
- Auto-response rules execute.
- Workflow rules execute.
- If there are workflow field updates, the record is updated again.
- If the record was updated with workflow field updates, before and after triggers fire one more time (and only one more time).
- Escalation rules execute.
- All DML operations are committed to the database.
- Post-commit logic executes, such as sending email.
Here is the diagram –
The Pdf version is here. Click Here
It is always important to keep the order of execution in mind. Please provide your feedback.
Hi Sudipta,
I have just started learning sfdc. I find this an interesting article, I have a small doubt in this order of execution,
in step no. 2 ('The new record field values are loaded from the request and overwrite the old values.') I think you are referring here to the values that are updated and Ignored in case of 'insert'.
Please correct me if I am wrong, help appreciated.
Thanks,
Noupada
Yes Noupada –
Please find the detail description below –
If the request came from a standard UI edit page, Salesforce runs system validation to check the record for:■Compliance with layout-specific rules
■Required values at the layout level and field-definition level
■Valid field formats
■Maximum field length
Salesforce doesn't perform system validation in this step when the request comes from other sources, such as an Apex application or a SOAP API call.
Salesforce runs user-defined validation rules if multiline items were created, such as quote line items and opportunity line items.
Let me know if you need any help. Thanks.