+ Start a Discussion

How to pass collection from flow to Apex?

Within a flow, I'm trying to pass a collection variable as input to an Apex element.  However, when I configure the Apex element, the collection variable does not show up as a selectable value in the Source dropdown.  In fact, there is not even a section within the dropdown for Collection Variables.  Anyone know why?

Collection Variables not selectable as input

Here are some relevant details:
  • The @InvocableMethod method that's being invoked accepts a list of Strings as its parameter (even though the name of the param is 'idList').
  • In the flow, record lookups populate various variables with record Id values.  A collection variable has been declared with Data Type = Text and Input/Output Type = Input Only.  An assignment variable is used to add the values of a couple of the Id variables into the collection variable.
  • I have double-checked by searching for the collection variable by name within the Inputs dropdown, and have confirmed it is not found.
I've been referencing this article but so far can't find any explanation:  https://developer.salesforce.com/docs/atlas.en-us.salesforce_vpm_guide.meta/salesforce_vpm_guide/vpm_designer_elements_apex.htm
Looks like the Cloud Designer doesn't support mapping sObject Collection variable to an Apex methods input/output parameters.
Source Link (https://developer.salesforce.com/docs/atlas.en-us.salesforce_vpm_guide.meta/salesforce_vpm_guide/vpm_designer_elements_apex.htm" target="_blank" target="_blank)

A solution to this could be to addup the ids/values into a comma seperated string using loop n assignment, then pass this string to the invocable apex method and use the native split method to create a new list. 

Though its being quite sometime since you posted your question but I just wanted to reply so that it might help someone ending up on this page.

Update:  Collection variable are supported with apex invocable methods.
Use something this 

    public static List<String>SampleMethod (List<List<Contact>> inputList){


    public static List<String>SampleMethod (List<List<String>> inputList){

Sobject collection variable or the collection variables will be available then.

Jake BackuesJake Backues
Thank you Nitesh! That worked for me.
Mohan ChanderMohan Chander
Hi Nitish,

How do i handle the list of strings thats coming from the flow?? Could you please share a sample code if you have any

any quick help is much appreciated.



Have a look at my answer above on May 16,2016.

Or another sample ( reference link : http://releasenotes.docs.salesforce.com/en-us/spring15/release-notes/rn_forcecom_flow_apex.htm)

global class lookUpAccountAnnotation {
   public static List<String> getAccountIds(List<String> names) {
      List<Id> accountIds = new List<Id>();
      List<Account> accounts = [SELECT Id FROM Account WHERE Name in :names];
      for (Account account : accounts) {
      return accountIds;
Does this help ?
Hi Nitish,
 Can you help with question on https://developer.salesforce.com/forums?communityId=09aF00000004HMGIA2#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Apex_Code_Development&criteria=OPENQUESTIONS&id=9060G0000005nrjQAA