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?

  • Deepak

    Member
    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

    Member
    December 30, 2021 at 12:13 pm

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

Viewing 1 - 2 of 2 posts

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos