I am trying to pass a list of records back into a flow as a collection variable but keep hitting this error Method does not exist or incorrect signature: void add(OpportunityTeamMember) from the type List<List> This is my code:
//invocable method to create OpportunityTeamMember records from a list of Opportunity Ids
@InvocableMethod(label='Create OTM Records for OOO' description='Given a list of Opportunity IDs, create OTM records from these IDs.')
public static List<List<OpportunityTeamMember>> createOTMRecords(List<InputVariables> inputVariables) {
//inputs
List<Opportunity> opps = inputVariables.get(0).Opportunities;
String UserId;
//outputs
List<List<OpportunityTeamMember>> otmOutputs = new List<List<OpportunityTeamMember>>();
for(Opportunity o : opps){
OpportunityTeamMember otm = new OpportunityTeamMember();
otm.OpportunityId = o.Id;
otm.UserId = UserId;
otm.TeamMemberRole = 'Mortgage Banker';
otm.OpportunityAccessLevel = 'Edit';
otmOutputs.add(otm);
}
system.debug('otmOutputs >>>>' + otmOutputs);
return otmOutputs;
}
public class InputVariables {
@InvocableVariable
public List <Opportunity> Opportunities;
@InvocableVariable
public String UserId;
}
Best Answer
As mentioned in the comment above, you need to add a List of Opportunity Team Member records to your output, not just a single Opportunity Team Member.
Assuming you're expecting to return a single list (which is how I read your supplied code), you should be able to do the following: