0

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;
    }
1
  • otmOutputs.add(otm) - you need to add a list of otms, not a singleton
    – cropredy
    Commented Mar 14, 2023 at 22:40

1 Answer 1

0

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:

    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>>();

        List<OpportunityTeamMember> otmList = new List<OpportunityTeamMember>();

        for(Opportunity o : opps){
            OpportunityTeamMember otm = new OpportunityTeamMember();
            otm.OpportunityId = o.Id;
            otm.UserId = UserId;
            otm.TeamMemberRole = 'Mortgage Banker';
            otm.OpportunityAccessLevel = 'Edit';
            otmList.add(otm);
        }
        otmOutputs.add(otmList);
        system.debug('otmOutputs >>>>' + otmOutputs);
        return otmOutputs;
    }    

    public class InputVariables {
        @InvocableVariable
        public List <Opportunity> Opportunities;

        @InvocableVariable
        public String UserId;
    }
1
  • Thank you so much @CallumMacErlich. Looks like I was just missing the inner list assignment. This helped me a lot.
    – Mona Weso
    Commented Mar 15, 2023 at 16:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .