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.
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.
Please find sample code below : 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