I have a flow that will be used to convert a list view of selected records of unknown type to custom object records. When the flow launches from a list view page, there will be a screen element where the user can select Field Labels from whatever object it is, to be mapped to FirstName, LastName, and MobilePhone fields.

I'm using invocable apex, called from the flow, to return a list of field label names (of type TEXT or PHONE) that will populate a pulldown menu so the user can select the right field to be mapped.

Here's one of my invocable apex classes:

global with sharing class SchemaFirstName {
@InvocableMethod(label='Get First Name options for this recordId')
global static List<String> getFirstNameFieldLabels(List<String> recordIds){
    Id recordId = recordIds[0];
    List<String> firstNameLabels = new List<String>();
    Boolean needFirstList = true;
    DescribeSObjectResult describeResult = recordId.getSObjectType().getDescribe();
    Map<String, Schema.SObjectField> fieldMap = describeResult.fields.getMap();
    Set<String> fieldNames = fieldMap.keySet();
        needFirstList = false;
    }else if(fieldNames.contains('firstname__c')){
        needFirstList = false;

    Schema.DisplayType stringType = Schema.SObjectType.Contact.fields.getMap().get('firstname').getDescribe().getType();

        for(String fieldName : fieldNames){
            if(fieldMap.get(fieldName).getDescribe().getType() == stringType){
                if(needFirstList) firstNameLabels.add(fieldMap.get(fieldName).getDescribe().getLabel());
    return firstNameLabels;


The invocable apex shows up in the Flow Builder, and I can specify the input list of Ids. I have created a collection variable in the Flow, firstNameOptions, to accept the list that is returned. enter image description here

However, when I try to create the Apex module in the flow, it won't recognize the firstNameOptions variable I created.

enter image description here

I've searched the docs and they don't seem to get into detail about using invocable apex and handling results.

  • It shows up for me.Try {!firstNameOptions} – sfdc May 15 '19 at 18:45
  • When I put in {!firstNameOptions}, it's giving me an error: The data type of the resource you entered isn't compatible. – PatMcClellan__c May 15 '19 at 18:50

I have copied and pasted your apex code in my org. Created firstNameOptions text variable in flow and it shows up under Apex Action.Please see below screenshot.

Deselect Allow Multiple values(Collection)

enter image description here enter image description here

  • Thanks for the effort. Not sure why it's not working for me. None of my variables show up in the Search variables dropdown... How do you have them marked re: input/output? I've tried all the combinations I can think of and still doesn't seem to work. – PatMcClellan__c May 15 '19 at 18:55
  • Try to Deselect Allow Multiple values(Collection) checkbox under firstNameOptions – sfdc May 15 '19 at 18:56
  • OH, just saw your comment about deselecting the collection. Why? Isn't a list<string> considered a collection? – PatMcClellan__c May 15 '19 at 18:56
  • OK, now I have the values in the variable... I just need to figure out how to get them into my choices for the picklist... :) – PatMcClellan__c May 15 '19 at 19:05

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.