You need to sign in to do that
Don't have an account?
Sonam Patil
Contact update on Account
Hi,
Can anyone help me with this scenario?
What Exactly, if( a.phone!= trigger.oldmap.get(a.id).phone) line does in the below scenario. What does it mean?
trigger contactUpdate_acc on Account (after update) {
list<contact> ctc =new list<contact>();
list<account> acc = new list<Account>();
for(Account a:trigger.new){
if( a.phone!= trigger.oldmap.get(a.id).phone){
acc.add(a);
}
}
}
Can anyone help me with this scenario?
What Exactly, if( a.phone!= trigger.oldmap.get(a.id).phone) line does in the below scenario. What does it mean?
trigger contactUpdate_acc on Account (after update) {
list<contact> ctc =new list<contact>();
list<account> acc = new list<Account>();
for(Account a:trigger.new){
if( a.phone!= trigger.oldmap.get(a.id).phone){
acc.add(a);
}
}
}
and Trigger.new returns a list of the new versions of the sObject records.
So in this line, it is comparing the new value with old value.
if( a.phone!= trigger.oldmap.get(a.id).phone)
a.phone will contain the new value from trigger.new and
trigger.oldmap.get(a.id).phone will fetch the old value of phone from the map.
All Answers
This line performs comparison between the previous and new value of phone field on Account object record. Trigger.oldMap contains the older versions of sobjects.
and Trigger.new returns a list of the new versions of the sObject records.
So in this line, it is comparing the new value with old value.
if( a.phone!= trigger.oldmap.get(a.id).phone)
a.phone will contain the new value from trigger.new and
trigger.oldmap.get(a.id).phone will fetch the old value of phone from the map.