function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC_LearnerSFDC_Learner 

Trigger.newmap & tirgger.oldmap

Where we use (trigger events)  trigger.newmap & trigger.oldmap?

 

raseshtcsraseshtcs
We can use the trigger.newmap and oldmap to compare if there were some changes done to the database and only then carry out the process which we want our trigger to do. e.g. You need to set a date type field called name change when the name of the record is changed using a trigger. You would check if the oldname and the new name are different or not
if(trigger.newmap,get("someid").name != trigger.oldmap,get("someid").name){
//Set the name change date
}
MoggyMoggy

you will use that in " before" triggers

harsha__charsha__c

Hi

 

here is the link for a brief on trigger context variable such as trigger.new/old/newmap/oldmap

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_context_variables.htm

 

Thanks

SFDC_LearnerSFDC_Learner

Can u confirm this.

 

We use,

Trigger.newmap -> before insert,before update, after insert and after update events.

Trigger.oldmap   -> before delete, before update and after update.

 

 

MoggyMoggy

each on its own your are nearly right, but why asking then?

 

combined  newMap & oldMap for comparing values only before makes sense

or how did you get the old values if you have just overridden the old values?

 

Documentation reads

newMapA map of IDs to the new versions of the sObject records.

Note that this map is only available in before update, after insert, and after update triggers.

oldMapA map of IDs to the old versions of the sObject records.

Note that this map is only available in update and delete triggers.

Ravi Shankar 121Ravi Shankar 121
Trigger.newmap -> before insert,before update, after insert and after update events.

This is sure beacuase i will test it