Salesforce Apex Trigger – Parent to Child Trigger Using List

Salesforce Apex Trigger – Parent to Child Trigger Using List

Hello guys,

In this blog, I am sharing the code of trigger it will update the contact field on updation or insertion of Account field. Here, I am just updating the contact field named Update_Checking__c whenever new value enters on parent object account field named Update_Checking__c.

For this, you need two custom field –

  1. Create custom field name as Update Checking in Account
  2. Create custom field name as Update Checking in Contact.

 


trigger UpdateFieldInContact on Account (after insert, after update) {
   
    List<Contact> conList = new List<Contact>();
    
    for(Account acc: Trigger.new)
    {
        String newValueInUpdateChecking = acc.Update_Checking__c;
        for(Contact con: acc.Contacts)
        {
            Contact conObj = new Contact();
            conObj.Id = con.Id; 
            conObj.Update_Checking__c = newValueInUpdateChecking;
            conList.add(conObj);
        }
    }
    Update conList;
}

Thanks.

Happy Coding.

0 Comments

Leave a Reply

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2018 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?