+ Start a Discussion
force noviceforce novice 

Triggers

When should we use Trigger.new, Trigger.old,Trigger.newMap & Trigger.old.

Best Answer chosen by Admin (Salesforce Developers) 
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi,

 

Following are the usages of trigger context variables,

 

Trigger.new >   for the operations of before insert/update  we can use this.

Trigger.old >   for the old operations like after update/delete we go for this.

Trigger.newMap  > A map of IDs to the new operations of the sObject records.
Note that this map is only available in before update, after insert, and after update triggers.

Trigger.oldMap > A map of IDs to the old versions of the sObject records.
Note that this map is only available in update and delete triggers.

 

Hope so this helps you...!

Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.

 

All Answers

StefgStefg

Hi,

 

There are some details here

 

Simply put Trigger.new is the new or updated object, Trigger.old is the object before the update (or possibly delete) and the Map versions are in the case of the trigger firing on a collection of objects.

 

Regards,

Stefan

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi,

 

Following are the usages of trigger context variables,

 

Trigger.new >   for the operations of before insert/update  we can use this.

Trigger.old >   for the old operations like after update/delete we go for this.

Trigger.newMap  > A map of IDs to the new operations of the sObject records.
Note that this map is only available in before update, after insert, and after update triggers.

Trigger.oldMap > A map of IDs to the old versions of the sObject records.
Note that this map is only available in update and delete triggers.

 

Hope so this helps you...!

Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.

 

This was selected as the best answer