You need to sign in to do that
Don't have an account?
Rohit 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.
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.
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,
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