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
jagdish nikam 9jagdish nikam 9 

order of exection

Hi All,

I am new to salesforce and just want to learn the order of exection in salesforce.

I have created custom validaton rule, lead assignemnt rule, before trigger and After trigger on lead object. I just want to check the order of execution using  Debug log. How can i do this? 
Best Answer chosen by jagdish nikam 9
M.sfM.sf
Hi,

For your order will be 
Before trigger
Validation rule
After Trigger
Lead Assignment rule


For Debug logs 
Goto SetUp->logs->debug logs->click on new
In Traced Entity Name enter you name. Selet till from what tim e to till waht time you require logs.
In debug leve select .New Debug Level set System,Validation,Database and other debug level to info\debug\fine based on your reuired and the details you needed.

For complete order of execution would be 
 
  1. Loads the original record from the database or initializes the record for an upsert statement.
  2. Loads the new record field values from the request and overwrites the old values.
  3. Executes all before triggers.
  4. 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 doesn't run a second time (when the request comes from a standard UI edit page) is the enforcement of layout-specific rules.
  5. Executes duplicate rules. If the duplicate rule identifies the record as a duplicate and uses the block action, the record is not saved and no further steps, such as after triggers and workflow rules, are taken.
  6. Saves the record to the database, but doesn't commit yet.
  7. Executes all after triggers.
  8. Executes assignment rules.
  9. Executes auto-response rules.
  10. Executes workflow rules.
  11. If there are workflow field updates, updates the record again.
  12. If the record was updated with workflow field updates, fires before update triggers and after update triggers one more time (and only one more time), in addition to standard validations. Custom validation rules, duplicate rules, and escalation rules are not run again.
  13. Executes processes.If there are workflow flow triggers, executes the flows. The pilot program for flow trigger workflow actions is closed. If you've already enabled the pilot in your org, you can continue to create and edit flow trigger workflow actions. If you didn't enable the pilot in your org, use the Flows action in Process Builder instead.
  14. Executes escalation rules.
  15. Executes entitlement rules.
  16. 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.
  17. If the parent record is updated, and a grandparent 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 grandparent record. Grandparent record goes through save procedure.
  18. Executes Criteria Based Sharing evaluation.
  19. Commits all DML operations to the database.
  20. Executes post-commit logic, such as sending email.
Ref:https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm

Thanks
 

All Answers

Nagendra ChinchinadaNagendra Chinchinada
Hi Jagadish,
Order will be as follows for ur transaction,
  1. Before trigger
  2. Validation rule
  3. After Trigger
  4. Lead Assignment rule
Refer below links for more info about order of execution,
http://www.asagarwal.com/2362/order-of-execution-rules-triggers-etc-in-salesforce-debug-log

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm

From Debug logs,
Set up debug logs against ur name(if u r executing), execute ur transaction(Insert/Update), open corresponding debug log.
If u go through entire log u will find above things in order.You can also search by word CODE_UNIT_STARTED,CODE_UNIT_FINISHED, Validation, Assignment .. etc
M.sfM.sf
Hi,

For your order will be 
Before trigger
Validation rule
After Trigger
Lead Assignment rule


For Debug logs 
Goto SetUp->logs->debug logs->click on new
In Traced Entity Name enter you name. Selet till from what tim e to till waht time you require logs.
In debug leve select .New Debug Level set System,Validation,Database and other debug level to info\debug\fine based on your reuired and the details you needed.

For complete order of execution would be 
 
  1. Loads the original record from the database or initializes the record for an upsert statement.
  2. Loads the new record field values from the request and overwrites the old values.
  3. Executes all before triggers.
  4. 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 doesn't run a second time (when the request comes from a standard UI edit page) is the enforcement of layout-specific rules.
  5. Executes duplicate rules. If the duplicate rule identifies the record as a duplicate and uses the block action, the record is not saved and no further steps, such as after triggers and workflow rules, are taken.
  6. Saves the record to the database, but doesn't commit yet.
  7. Executes all after triggers.
  8. Executes assignment rules.
  9. Executes auto-response rules.
  10. Executes workflow rules.
  11. If there are workflow field updates, updates the record again.
  12. If the record was updated with workflow field updates, fires before update triggers and after update triggers one more time (and only one more time), in addition to standard validations. Custom validation rules, duplicate rules, and escalation rules are not run again.
  13. Executes processes.If there are workflow flow triggers, executes the flows. The pilot program for flow trigger workflow actions is closed. If you've already enabled the pilot in your org, you can continue to create and edit flow trigger workflow actions. If you didn't enable the pilot in your org, use the Flows action in Process Builder instead.
  14. Executes escalation rules.
  15. Executes entitlement rules.
  16. 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.
  17. If the parent record is updated, and a grandparent 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 grandparent record. Grandparent record goes through save procedure.
  18. Executes Criteria Based Sharing evaluation.
  19. Commits all DML operations to the database.
  20. Executes post-commit logic, such as sending email.
Ref:https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm

Thanks
 
This was selected as the best answer
jagdish nikam 9jagdish nikam 9
Thank you so muh for your answers!!!!
phanip adminphanip admin
Order of Exection

1. Old Record loaded from Database.
2. New Record values overwrite old record.
3. System Validataion Rules.
4. All the Apex before triggers.
5. Custom validation Rules
6. Record saved to database (Not Commtted).
7. Record reloaded from database.
8. All Apex After Triggers.
9. Assignment Rules.
10. Auto Response Rules.
11. Workflow Rules.
12. Escaltion Rules.
13. Parent Rollup summary formula value update (if present)
14. Database commit.
15. Post-commit logic (Sending Email).