Wednesday, 15 August 2018

Order of execution of apex code

1. Before triggers:
     If we update child records in before triggers then parent record automatically update.
2. Validation rules:
 If validation matches the criteria then error will populate in same page.
Runs most system validation steps again, such as verifying that all required fields have a non-null value, and runs any user-defined validation rules. The only system validation that Salesforce does not run a second time (when the request comes from a standard UI edit page) is the enforcement of layout-specific rules.
*Note: Saves the record to the database, but does not commit yet.

3. After Triggers:
4. Assignment Rules:
5. Auto Response Rules:
6. Workflow Rules:
If there are workflow field updates, updates the record again.
7. Escalation Rules:
       If the record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Parent record goes through save procedure.
     If the parent record is updated, and a grand-parent record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Grand-parent record goes through save procedure.
Executes Criteria Based Sharing evaluation.
Commits all DML operations to the database.

8.Executes post-commit logic, such as sending emails



simple steps:
==============
Order of Events
  1. Original record is loaded or new record is initialized
  2. Fields values are loaded into sObjects
  3. System validations rules are executed:
  4. Before triggers are executed
  5. System validations rules are run again and custom validation rules are checked.
  6. Duplicate rules are executed
  7. Record is saved but not committed
  8. After triggers are executed
  9. Assignment rules are executed
  10. Auto-response rules are executed
  11. Workflow rules are executed
  12. Before triggers,system validation rules and after triggers are executed due to workflow field updates
  13. Processes are executed
  14. Escalation rules are executed
  15. Entitlement rules are executed
  16. Rull-up summary fields and cross-object formula fields are updated
  17. Updated parent and grand parent records are saved
  18. Criteria based sharing rules are evaluated
  19. DML operations are committed to the database
  20. Post-commit logic is executed

No comments:

Post a Comment