You need to sign in to do that
Don't have an account?
nilesh walke
Whenever an account phone is modified, update all the contacts of the account
public static void ForQnoSIX(List<account> oldAccount, List<account> Ac4){
List<contact> conList=[select lastname,otherphone,accountid,mobilePhone from contact
where accountid IN: Ac4];
map<id,string> oldAccidVsPhone= new map<id,string>();
map<id,string> newAccidVsPhone= new map<id,string>();
for(account newAcc: Ac4){
for(account oldAcc: oldAccount){
if(newAcc.phone!=oldAcc.phone && oldAcc.id==newAcc.id){
oldAccidVsPhone.put(oldAcc.id,oldAcc.phone);
newAccidVsPhone.put(newAcc.id,newAcc.phone);
}
}
}
list<contact> updateContactList= new List<contact>();
for(contact con: conList){
if(oldAccidVsPhone.containskey(con.accountid)){
con.otherphone=oldAccidVsPhone.get(con.accountid);
con.mobilePhone=newAccidVsPhone.get(con.accountid);
updateContactList.add(con);
}
}
if(updateContactList.size()>0){
update updateContactList;
}
}
i need test class for it
thanks for helping me out
List<contact> conList=[select lastname,otherphone,accountid,mobilePhone from contact
where accountid IN: Ac4];
map<id,string> oldAccidVsPhone= new map<id,string>();
map<id,string> newAccidVsPhone= new map<id,string>();
for(account newAcc: Ac4){
for(account oldAcc: oldAccount){
if(newAcc.phone!=oldAcc.phone && oldAcc.id==newAcc.id){
oldAccidVsPhone.put(oldAcc.id,oldAcc.phone);
newAccidVsPhone.put(newAcc.id,newAcc.phone);
}
}
}
list<contact> updateContactList= new List<contact>();
for(contact con: conList){
if(oldAccidVsPhone.containskey(con.accountid)){
con.otherphone=oldAccidVsPhone.get(con.accountid);
con.mobilePhone=newAccidVsPhone.get(con.accountid);
updateContactList.add(con);
}
}
if(updateContactList.size()>0){
update updateContactList;
}
}
i need test class for it
thanks for helping me out
You can try the below snippet:
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
Try Below Code Made A Small Change In Your Class Please Mark It As Best Answer If It Helps
Thank You!