Activity Forums Salesforce® Discussions Write a trigger on child object, where parent is an external object, to copy parent record fields to child

  • PRANAV

    Member
    August 29, 2016 at 5:01 am

    Hi Tanu,

    Try this code:

    trigger CopyAccPhoneToConPhone on Account (after insert, after update) {
    Map<Id, String> m = new Map<Id, String>();
    list<contact> conlist = new list<contact>();
    for (contact a : [select id, phone, Contact.AccountId, account.phone from contact where Contact.AccountId IN: trigger.new] ) {
    if(a.accountid != null){
    a.phone = a.account.phone;
    conlist.add(a);
    }

    }
    update conlist;
    }

    Hope this helps you.

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos