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
Sandeep Reddy 288Sandeep Reddy 288 

Write an apex program, to Synchronize the Accounts Data into the associated Contact Records automatically based on the Account Name

Write an apex program, to Synchronize the Accounts Data into the associated
        Contact Records automatically based on the Account Name, as below.
            Acocunt Field            Copied to Contact
            ------------------------------------------
              Account:Phone                --->     Contact:Phone
              Account:Fax                --->     Contact:Fax
              Account:BillingStreet     --->     Contact:MailingStreet    
              Account:BillingCity       --->    Contact:MailingCity      
              Account:BillingState      --->    Contact:MailingState     
              Account:BillingPostalCode --->    Contact:MailingPostalCode
              Account:BillingCountry    --->    Contact:MailingCountry   
Sandeep Reddy 288Sandeep Reddy 288
just want apex class code and anonymus window
AnkaiahAnkaiah (Salesforce Developers) 
Hi Sandeep,

try with below code.

apex class:
public class AccountContactSync {
    
    public static void contactssync(){
       map<id,Account> accmapwithname = new map<id,Account>();

        for(account acc :[select id,Name,phone,Fax,BillingStreet,BillingCity,BillingState,BillingPostalCode,BillingCountry from account limit 2000]){
          accmapwithname.put(acc.id,acc);  
        }
       List<contact>  conlistupdate = new List<contact>();
        for(contact con:[select id,Accountid,phone,Fax,MailingStreet,MailingCity,MailingState,MailingPostalCode,MailingCountry from contact where accountid=:accmapwithname.keyset()]){
            if(accmapwithname.containskey(con.AccountId)){
                con.fax = accmapwithname.get(con.AccountId).fax;
                con.phone = accmapwithname.get(con.AccountId).phone;
                con.MailingStreet = accmapwithname.get(con.AccountId).BillingStreet;
                con.MailingCity = accmapwithname.get(con.AccountId).BillingCity;
                con.MailingState = accmapwithname.get(con.AccountId).BillingState;
                con.MailingPostalCode = accmapwithname.get(con.AccountId).BillingPostalCode;
                con.MailingCountry = accmapwithname.get(con.AccountId).BillingCountry;
                conlistupdate.add(con);
            }
        }
        update conlistupdate;
        system.debug('conlistupdate=='+conlistupdate);
        
    }

}

anonymus window run the below 
AccountContactSync.contactssync

If this helps, Please mark it as best answer.

Thanks!!