Activity Forums Salesforce® Discussions Is there any need of map when we can insert & update using List only in contact mailing address?

  • Is there any need of map when we can insert & update using List only in contact mailing address?

    Posted by Deepak on March 4, 2020 at 1:44 pm
    trigger update_MailingAddress on Contact(before insert,before update) {
    set<id> accountIdset=new set<id>();
    
    for(Contact con:trigger.new){
    if(con.AccountId!=null){
    accountIdset.add(con.AccountId);
    }
    }
    list<account> accList = [select id,billingCity,billingState,billingStreet,billingCountry from Account where id iN : accountIdset];
    for(Account acc : accList){
    for(contact con :trigger.new)
    {
    con.MailingCity = acc.billingCity;
    con.MailingState = acc.billingState;
    con.MailingStreet = acc.billingStreet;
    con.MailingCountry = acc.billingCountry;
    }
    }
    }

     

    • This discussion was modified 4 years, 9 months ago by  Deepak.
    Deepak replied 4 years, 9 months ago 1 Member · 0 Replies
  • 0 Replies

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos

Popular Salesforce Infographics