I have picklist field "Location" on opportunity object and text field "Type" on Account object. I want to copy the picklist values from all opportunities related to the account and display it on "Type" field on account separated by comma. I tried using process builder but didn't work, tried using below trigger but not working, any help?
trigger UpdateAmount on Opportunity (after insert, after update) { Map parentOpps = new Map(); Set listIds = new Set();
for (Opportunity childObj : Trigger.new) { listIds.add(childObj.AccountId); }
parentOpps = new Map([SELECT id, Opp_Location__c , (SELECT ID,Location_Type__c FROM Opportunities) FROM Account WHERE ID IN :listIds]);
List lstAccount = new List();
for(Account acct:parentOpps.values())
{
List strType = new List();
for(Opportunity oppty:acct.Opportunities)
{
strType.add(oppty.Opp_Location__c);
}
acct.Location_Type__c = String.join(strType,',');
}
update parentOpps.values(); }