8

There are methods like:

@InvocableMethod
public static List<Id> loadContact(List<String> ids) {

or

@InvocableMethod
public static List<Contact> loadContact(List<String> ids) {

I'd like to assign output to collection variable but only regular variable is available. If I try to created collection variable, validation prevents collection variable assignment:

enter image description here

The requirement is the following:

  • 1st screen - dynamic multi choice field to collect contacts/contact ids
  • 2nd screen - to display radio dynamic field with contacts selected on the 1st screen

So I thought to use apex to pass string like 'id;id;id' and return List< Id > to use that list as filter on the second screen

Thanks in advance.

6

I had the same issue and found the answer on the developer forum, posted by user Chad Barbour.

Basically your @invocableMethod must return a list of lists,

 public static List<List<PriceBookEntry>> getPBE(){
      List<PriceBookEntry> PBEs = [Select Id, Product2Id from pricebookentry where Product2.Family = 'test'];
      List<List<PriceBookEntry>> listOfPBELists = new List<List<PriceBookEntry>>();
      listOfPBELists.add(PBEs);
      return listOfPBELists;
 }

With this, in visual flow, you can assign the output to an Sobject collection of the same type and use it like you would any other sobject collection.

2

You need to use an Apex Plug-in to do this. See the Spring '15 Release Notes for an example that uses an @InvocableMethod. In the Apex Code Developer's Guide, you'll find more on the Passing Data to a Flow Using the Process.Plugin Interface.

  • Do I have to understand that @InvocableMethod are not able to return any parameter to a flow? If it can only return a collection, but the flow can't recover a collection from such methods, there's sort of a dead end there. We have to use the (heavier) plugin interface necessarily then? Regards Frederic – Frederic Provot Sep 22 '16 at 16:56
  • If you look at the example at developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…, I believe you could possibly return a map <integer, list<string>> of size = 1 by creating a class that does what you want for only one record. The integer could be your "loop count" in the flow that you'd pass as a param to your class. If I'm understanding your question, you'd then assign the list<string> in the map to your collection variable. – crmprogdev Sep 23 '16 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.