Points to consider with Trigger Context Variables:

  • Trigger.new and Trigger.old cannot be used in Apex DML Operations.
  • You can use an sObject to change its own field values using trigger.new but only in before triggers.
  • Trigger.old is always read-only.
  • You can not delete Trigger.new.
  • Upsert and merge events do not have their own triggers, instead they fire other triggers based on the events as a result of merge operation.

Execution Order of Upsert & Merge Operation:

  • In case of upsert operation:
    • The records which are getting inserted fires before & after insert triggers.
    • The records which are getting updated fires before and after update triggers.
  • In case of merge operation:
    • The records which are deleted due to merge operation fires a single delete event (that means before & after delete will be fired only once, irrespective of the number of records deleted).
    • The master record fires a single update event (before & after update) but no triggers are fired for the child records which are reparented as a result of merge operation.

Order of Events in a Merge Operation:

  1. Before delete trigger fires.
  2. Deletes record from database.
  3. After delete trigger fires.
  4. Before update for master record fires.
  5. Record gets updated.
  6. After update for the master record fires.

Our Recent Blog

Share This Post