You need to sign in to do that
Don't have an account?
Akshay Alandkar
want test class for this one
public void phone1(List<account> oldAccount, List<account> newAccount)
{
List<contact> conList=[select lastname,otherphone,accountid,mobilePhone from contact where accountid IN: newAccount];
map<id,string> oldAccidVsPhone= new map<id,string>();
map<id,string> newAccidVsPhone= new map<id,string>();
for(account newAcc: newAccount)
{
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;
}
}
}
{
List<contact> conList=[select lastname,otherphone,accountid,mobilePhone from contact where accountid IN: newAccount];
map<id,string> oldAccidVsPhone= new map<id,string>();
map<id,string> newAccidVsPhone= new map<id,string>();
for(account newAcc: newAccount)
{
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;
}
}
}
First you need to try your self, you should create from your side after that if you have any issue then we are ready for Assist.
I hope you understand my point
Regards
Mukesh
I hope the implementation itself has some issue. Can you please confirm if your requirement is as below.
If user is updating the account phone field then put the old phone number in the otherphone field and new phone number in mobilePhone in all the related contacts?
Thanks,
K. Sai Praveen Kumar.