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
Rohit kumar singh 1Rohit kumar singh 1 

Can SomeOne Explain the working/control flow

trigger Oldtrigger on Contact (before update,after insert) {
for (Contact account : Trigger.new) {
Contact oldAccount = Trigger.oldMap.get(account.ID);
system.debug('#####'+oldAccount);
}
}
How is it working and where I can see the output.
Nishad KNishad K
Hi Rohit,
Trigger.oldMap is only available in update and delete triggers. so you can't use in after insert,

See the below links:

https://trailhead.salesforce.com/en/apex_triggers/apex_triggers_intro

Trigger Context Variables (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables.htm)


Regards,
Vivek C 1Vivek C 1
Hi Rohit,

The trigger.oldMap context variable is only available in the Update and and Delete triggers.

In your trigger, When you update the account name of a Contact (Supose you change the account name of a Contact from ABC to XYZ ). The the Update trigger fores and in the Trigger.oldMap it stores the previous value of ABC. So in the duebug you will get the account id of ABC.

Hope this is pretty much clear to you !.

Regards,
VIvek