Monday, October 28, 2019

AVAILABILITY OF TRIGGER.NEW, TRIGGER.OLD, TRIGGER.NEWMAP, TRIGGER.OLDMAP



Today, we will be learning about the availability of the following trigger variables: TRIGGER.NEW, TRIGGER.OLD, TRIGGER.NEWMAP, and TRIGGER.OLDMAP. These trigger variables are used in database triggers to access data during different trigger events, such as insert, update, delete, and undelete operations.

TRIGGER.NEW and TRIGGER.NEWMAP hold the new values of the records being inserted or updated.

TRIGGER.OLD and TRIGGER.OLDMAP hold the previous values of the records before an update or delete operation.

We will explore when each of these variables is available, depending on the type of trigger event (before insert, after insert, before update, after update, before delete, after delete, and after undelete). Understanding their availability is crucial for correctly managing data within triggers in your database.

difference between trigger newmap and trigger oldmap in salesforceBefore Insert:
TRIGGER.NEWMAP is not available because the record ID is not generated yet; the ID is assigned only when the record is inserted into the database.

Before Insert:
TRIGGER.OLD and TRIGGER.OLDMAP are not available, as no old data exists for a new record being inserted into the database.

After Insert:
TRIGGER.OLD and TRIGGER.OLDMAP are not available because there is no old data for the newly inserted record.

Before Update and After Update:
TRIGGER.NEW, TRIGGER.NEWMAP, TRIGGER.OLD, and TRIGGER.OLDMAP are all available because both new and old data are accessible during update operations.

Before Delete and After Delete:
TRIGGER.NEW and TRIGGER.NEWMAP are not available because no data is being updated; we are only deleting the record.

After Undelete:
TRIGGER.NEW and TRIGGER.NEWMAP are available because the record is restored. The ID of the record remains the same after it is undeleted.

4 comments:

  1. Hi Very Good Explanation Thanks for sharing Knowledge with us ......

    ReplyDelete
  2. thank you a lot, explanation is very well. Understood very quickly.

    ReplyDelete
  3. This is the best blog I have ever seen to understood the trigger context variables. Very easy to learn and understand.

    ReplyDelete