Populate child records field value on parent record
Populate child records field value on parent record by using apex trigger when child record is inserted. *** trigger ContactTrigger on Contact (after insert) { if(Trigger.isAfter && Trigger.isInsert){ ContactTriggerHandler.populateNameOnParent(Trigger.new); } } *** *** // populate child records name on parent field when child record is inserted public static void populateNameOnParent(List<Contact> contactList){ Map<Id,List<Contact>> contactWithAccId = new Map<Id,List<Contact>>(); Set<Id> accountIds = new Set<Id>(); List<Account> accountsList = new List<Account>(); String concatenateString; for(Contact cont : contactList){ if(cont.AccountId != null) { accountIds.add(cont.AccountId); // get account id from contacts } } // get all contacts related to account ids if(accountIds.size() > 0