Activity Forums Salesforce® Discussions How this is updating contact's mailing address related to account's billing address?

  • How this is updating contact's mailing address related to account's billing address?

    Posted by Deepak on March 4, 2020 at 1:38 pm
    trigger ContactMailAddr on Contact (before insert, before update) 
    {
        set<id> setofaccountIds=new set<id>();
        
        for(Contact contact:trigger.new)
        {
            if(contact.AccountId!=null)
            {
                setofaccountIds.add(contact.AccountId);
            }
        }
        map<id,account> accountmap=new map<id,account>([select id,
                                                        billingCity,
                                                        billingState,
                                                        billingpostalcode,
                                                        billingStreet,
                                                        billingCountry from account where id in :setofaccountIds]);
        for(contact contact :trigger.new)
        {
                contact.MailingCity = accountmap.get(contact.AccountId).billingCity;
                contact.MailingState = accountmap.get(contact.AccountId).billingState;
                contact.MailingStreet = accountmap.get(contact.AccountId).billingStreet;
                contact.MailingCountry = accountmap.get(contact.AccountId).billingCountry;
                contact.MailingPostalCode = accountmap.get(contact.AccountId).billingpostalcode;
        }
    }
    
    

     

    Supriya replied 2 years, 3 months ago 2 Members · 1 Reply
  • 1 Reply
  • Supriya

    Member
    December 30, 2021 at 12:13 pm

    Hi,
    Could you please tell how to write Test Class ..

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos