Wednesday, May 22, 2013

Trigger.new vs Trigger.old  


Trigger.new

     Trigger.new stores new values of a record. This basically means that when you edit a record and save it, your trigger would be called and the values that you have changed will be available in Trigger.new.

     Returns a list of the new versions of the sObject records.Note that this sObject list is only available in insert and update triggers, and the records can only be modified in before triggers.

Trigger.old  

       Trigger.old stores the old values of a record. This basically means that when you edit a record and save it, your trigger would be called and the values that were available before you edited the record would be stored in Trigger.old. 

Returns a list of the old versions of the sObject records. Note that this sObject list is only available in update and delete triggers.

Context Variable Considerations 

1.Trigger.new and trigger.old cannot be used in Apex DML operations.

2.You can use an object to change its own field values using trigger.new, but only in before triggers.

3.In all after triggers, trigger.new is not saved, so a runtime exception is thrown.

4.Trigger.old is always read-only.You cannot delete trigger.new.

No comments:

Post a Comment