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 

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
v varaprasadv varaprasad
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 it helps you.
If the above information is informative please mark it as the best answer.

if you any other assistance please let me know.

Thanks
Varaprasad