function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
iswarya sekar 7iswarya sekar 7 

Hi everyone!!i need to create a custom field in parent case,where the child case emails should be auto populated in that custom field.for example a parent case has three child cases.then the three email should be there in that custom field with semicolon.

Best Answer chosen by iswarya sekar 7
NagendraNagendra (Salesforce Developers) 
Hi Iswarya,

Please find sample code below : 
trigger ContactNamesOnAccount on Contact (after update, after insert) 
{    
   
   Set<id> accIdList = new Set<id>();
   for(Contact con : Trigger.new)
   {
    accIdList.add(con.accountid);
   }

   List<Account> accUpdateList = new List<Account>();
   for(Account acc : [Select id, name, Contact_Names__c, 
                             (Select Id, name, LastName From Contacts) 
                        From Account Where Id In : accIdList])
{
    List<String> lstSrting = new List<String>();
    for(Contact con : acc.contacts)
    {
        lstSrting.add(con.lastname);
    }
    acc.Contact_Names__c = String.join(lstSrting, ',');
}
     accUpdateList.add(acc);
   }    
   update accUpdateList;
}
Hope this helps.

Kindly mark this as solved if the information helps so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra