function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
David Gunn 17David Gunn 17 

Can't pass results back from invocableMethod in Apex class to flow through custom object

(If should be posted to the developers forum I apologize - let me know and I'll post there instead.)

I can't set up my flow to receive a return value from an invocablemethod. :(

I'm building an Apex class named Temp that contains an invocablemethod named performApproval.  It returns a return code and string message through a custom object:
global without sharing class Temp {
	
    @InvocableMethod
    public static List<Apex_Result__c> performApproval(List<MyInvocableVariables> myVariablesList) {
		List<Apex_Result__c> resultList = new List<Apex_Result__c>();
		Apex_Result__c result = new Apex_Result__c();
		result.Return_Code__c = 1;
		result.Message__c = 'Testing';    	
		resultList.Add(result);
		return resultList;
	}

	global class MyInvocableVariables {
		@InvocableVariable(label='Opp ID' required=true) 
		global Id oppID; 		
	}
}
I call the method from a flow, and I defined an SObject collection variable named Results to receive the results of the call. However, when I attempt to specify that the method's output should go into that variable I only get the option to create a new variable:

Screenshot showing I only see Create New

Can anyone explain why I can't select an existing variable?  Even if I create a new variable it doesn't use it or allow me to select it.
David Gunn 17David Gunn 17
Problem solved.  Thanks to Vince's reply on https://salesforce.stackexchange.com/questions/76787/flow-invocablemethod-how-to-assign-output-to-collection-sobject-collection-v.  I had to return a list of lists from my invocable method:
 
global without sharing class Temp { 
    @InvocableMethod 
    public static List<List<Apex_Result__c>> performApproval(List<MyInvocableVariables> myVariablesList) { 

        List<Apex_Result__c> resultList = new List<Apex_Result__c>(); 
        Apex_Result__c result = new Apex_Result__c(); 
        result.Return_Code__c = 1; 
        result.Message__c = 'Testing';       
        resultList.Add(result); 
        return resultList; 
    } 

    global class MyInvocableVariables { 
        @InvocableVariable(label='Opp ID' required=true)  
        global Id oppID;         
    } 
}
Now in my flow when I go to specify a variable to receive the output from the performApproval method I see Results (which is an SObject Collection Variable based on my custom Apex_Results__c object) in the list.
Sébastien RichardSébastien Richard
Hi,
How are you doing to return resultList (line 10) which is a list whereas your fonction returns a list of list (line 3) ? 
I would like do the same. My goal is to use an @InvocableMethod to pass a text as input and return a list of string as output.
Thanks a lot for your help.