This is the example I am attempting to follow: Link Here
I have the parent object Accounts with a field for the concatenated information labeled Systems_Pick_Text__c
My children objects of Opportunities with a multi-picklist of Systems_Pick__c.
I want to show all chosen system pick items from the child objects in one field, (Systems_Pick_Text__c ) on the parent object (Account).
Here is what I have currently in the Apex class.
public class SystemsPickText {
{
@InvocableMethod
//Method that accepts the AccountIds from the Process and executes the de-dupe and update logic
public static void updateSystemsPickInfo(List<Id> AccountIds){
Id accountId = AccountIds[0];
Account acc = [SELECT Id, Systems_Pick_Text__c FROM Account WHERE Id=: accountId];
acc.Systems_Pick_Text__c = null;
list<Opportunity> oppSystemsPick = new List<Opportunity>();
oppSystemsPick = [SELECT Id, Systems_Pick__c, AccountId FROM Opportunity WHERE AccountId =: accountId];
//Use of Set allows us to de-dupe System Pick field values on the Opp object
if (oppSystemPick.size()>0){
Set<String> systems = new Set<String>();
for(Opportunity oppObj : oppSystemPick){
if(!String.isBlank(oppObj.Systems_Pick__c)){
systems.add(oppObj.Systems_Pick__c);
}
}
if (!systems.isEmpty()){
for(String system:systems){
if(!String.isBlank(acc.Systems_Pick_Text__c)){
//Concatenation of all system values and dumping onto the Account field
acc.Systems_Pick_Text__c = acc.Systems_Pick_Text__c + ' , ' +system;
}
else{
acc.Systems_Pick_Text__c = system;
}
}
}
}
try{
update acc;
}catch(Exception e){
system.debug('Exception:::'+e.getMessage());
}
}
}
}