You need to sign in to do that
Don't have an account?
Prasanth R
if phone number update in account,,it should pop up contact phone number using map
i'm beginner in trigger.i tried below code but stucked in midway..kindly someone help
trigger practiceacc on Account (after update){
List<contact> ctlt = new List<contact>();
set<Id> st = new set<Id>();
for(Account acc:Trigger.new){
st.add(acc.id);
}
Map<Id,Account> mapacc = new new Map<Id,Account>([Select Id,Name,Phone from contact where AccountId in:st]);
for(Account obj1:Trigger.new){
if(mapacc.get(obj1.Accountid).obj1=Phone)
}
update ctlt;
}
trigger practiceacc on Account (after update){
List<contact> ctlt = new List<contact>();
set<Id> st = new set<Id>();
for(Account acc:Trigger.new){
st.add(acc.id);
}
Map<Id,Account> mapacc = new new Map<Id,Account>([Select Id,Name,Phone from contact where AccountId in:st]);
for(Account obj1:Trigger.new){
if(mapacc.get(obj1.Accountid).obj1=Phone)
}
update ctlt;
}
Try Below Trigger Please Mar It As Best Answer If It Helps
Thank You!
Map<String, String> MapAcc= new Map<String, String>();
This map will hold Key as Accound Id and Value as Account Phone
list<contact> lstcon =[select id,phone,AccountId from contact Where AccountId IN : st ]
This quey will give you all related contact assosciated with account on which update are being done.
if(MapAcc.containsKey(Con.AccountId ).----> now after iterating contact list with this condition we are checking whether that Contact Id is present in map which is created.
if yes then updating the value of contact phone
MapAcc.get(Con.AccountId)---->. in this line our key is Con.AccountId and with get function we are getting the value which was stored earlier in map i.e phone.
Hope able to explain.
Thanks!