I'm calling an apex action to an invocable method which needs to return a wrapperList. Below is my invocable method & I'm having trouble accessing the returned wrapperList within my flow so that I can loop over the list to map each wrapper record values like (Link -> CorporateLink__c, meu.Id -> Id etc). This is how my flow & the apex action looks.

enter image description here
enter image description here The contactIds list input variable here will usually gets assigned with all records when there are like 100 records trigger this flow at once. correct?

public class handleFlowrelatedApexactionMethods{
    @InvocableMethod(label='Get wrapList' description='Returns wraplist')
    public static List<List<wrappercls>> businessprocess(List<Id> contactIds){
        Map<id,Wrappercls> wrapObjRecords = new map<Id,Wrappercls>();
        for(conIds con : contactIds){
            //add business use cases

            //adding the results to the below map by constructing the wrap record
            wrapObjRecords.put(Id, new Wrappercls(AccountId, ContactId, PhoneNumber, Link, meu));
        //returning the list of wrapperObjrecords
        return new List<List<wrappercls>>{wrapObjRecords.values()};

    public class Wrappercls{
        @AuraEnabled @InvocableVariable public Id AccountId;
        @AuraEnabled @InvocableVariable public Id ContactId;
        @AuraEnabled @InvocableVariable public String PhoneNumber;
        @AuraEnabled @InvocableVariable public String Link;
        @AuraEnabled @InvocableVariable public MessagingEndUser meuRec;
        public OutboundCommunicationWrapper(Id AccountId, Id ContactId, String PhoneNumber,String Link, MessagingEndUser meuRec){
            this.AccountId = AccountId;
            this.ContactId = ContactId;
            this.PhoneNumber = PhoneNumber;
            this.Link = Link;
            this.meuRec = meuRec;

The trouble that I am facing currently is - How do I have the collection variable created that reflects the wrapper object structure & how do I assign the apexAction outcome(returned wrapperList from apex) to this collectionvariable so that I can loop over this collectionvariable & assign/handoff data to next steps (send SMS). Wanted to hear from fellow developers/experts on how to handle this. Appreciate your help! Thanks!

  • As written, this isn't properly bulkified. contactIds[0] corresponds to the [0} element of the return value, contactIds[1] corresponds to the [1]` element of the return value.
    – cropredy
    Commented Feb 9 at 22:59
  • @cropredy So if a dataloader updates 100 records which meet this flow teigger criteria, my assumption is each record will be collected in contactids list by adding record.nbps_primary_contact value until it reaches the last record. Then all those will be passed to apex action. Now apex action has 100 ids in contactids list..Confused on what you’re referring to here. Please share some more details. Thanks!
    – Sam
    Commented Feb 11 at 20:29
  • that is correct, apex action is called once. But the apex action return needs to return 100 list elements, where each element[i] is a list of wrappers that apply to incoming contact[i]
    – cropredy
    Commented Feb 12 at 19:14
  • @cropredy so in this line wrapObjRecords.put(Id, new Wrappercls(AccountId, ContactId, PhoneNumber, Link, meu)); we're adding all the 100 records to a map here by iterating using for loop & retuning all back in the last line. If I'm missing something here,c an you please share the udpated code here. Appreciate your help!
    – Sam
    Commented Feb 12 at 21:10
  • Also was going through this trailhead.salesforce.com/trailblazer-community/feed/… looking at "Second correct approach:" from Gulshan Raj's answer & looks like the above is valid. Is it not?
    – Sam
    Commented Feb 12 at 21:22

1 Answer 1


Here is the basic structure you will need.

  • results[0] should be a list of 0..n WrapperCls corresponding to contactIds[0]

  • results[1] should be a list of 0..n WrapperCls corresponding to contactIds[1]

  • ...

    public static List<List<wrappercls>> businessprocess(List<Id> contactIds){
      List<List<WrapperCls>> results = new List<List<WrapperCls>>();
      for(conIds con : contactIds){
          List<WrapperCls> wrappers = new List<WrapperCls>();
          // cater for 0+ WrapperCls per ContactId
          WrapperCls wrapper = new WrapperCls(AccountId, ContactId, PhoneNumber, Link, meu);
          results.add(wrappers);  // ith Contact puts wrappers into results[i]
      // return bulkified results, 1 per Interview
      return results;


Now, if you are doing SOQL or DML in the invocable, you'll need to cross-reference between the ith contactId and a map of contactId => WrapperCls[]. I find the easiest way to do this is to create a new inner class (call it Interview that contains the ith input and ith output. Then, you can have a list of Interviews and a Map of contactId => Interview

You must log in to answer this question.

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