function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Akshay AlandkarAkshay 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;
        }
    }
   }
mukesh guptamukesh gupta
Hi Akshay,

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
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Akshay,

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.