+ 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);
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:


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

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 !.