html code

Execution of Trigger and Workflow – A practical Analysis

Target Record:

A Case record with Status =”New” in Database. There is trigger which updates the value of Status =”Working” in before update event. There is workflow too which updates to Status to “Escalated”. So, we are going to analyze how system behaves in these scenarios:

Lets play as below:

  1. Opened Case. It’s status = ‘New’.
  2. Changed the status manually to “Assigned”
  3. Before Update:
    1. Debug the old & new value
      • Old value is => New
      • New value is =>Assigned
    2. Update the status to Working
      • Status = “Working”
  4. After Update:
    1. Debug the values
      • Old value is still => New
      • New value is =>Working
  5. After that, workflow field update executes. And updates the status to “Escalated”
  6. Now, trigger executes again 🙂
  7. Before Update:
    1. Debug the old & new value
      • Old value is still => New
      • New value is =>Escalated
    2. Update the status to WorkingStatus = “Working”
  8. After Update:
    1. Debug the values – Old value is still => New
    2. New value is =>Working

P.S: In all events, old value remains same whatever it was in database.

Post credit: Paramvir Singhhttps://www.linkedin.com/in/paramvir-singh-54906ba0