
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 –
- Create custom field name as Update Checking in Account
- Create custom field name as Update Checking in Contact.
Don't forget to check out: Salesforce Apex Trigger - Child to Parent Trigger using Map
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.