Activity Forums Salesforce® Discussions How to connect a trigger from more than two sobject in salesforce?

  • PRANAV

    Member
    August 30, 2016 at 8:45 am

    Hi Mohit,

    Yes, We can connect two object which has some sort of relationship between them like in account and contact.

    Here is a sample code, which is on account object. In this trigger when an account is inserted or updated, then its related contact has same phone number in its record.

    trigger CopyAccPhoneToConPhone on Account (after insert, after update)
    {
    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