Pass Variables from flow to Apex, Cannot access invocable variable

All we need is an easy explanation of the problem, so here it is.

I am trying to pass two variables from Flow to apex. One is a collection variable and another is just a string.

Collection Variable is passed in personIds

And Passing String in inputName

I am trying to loop on the Collection variable and update the name, But i am not able to access the input name, as i can only create one method for personIds.

    global class lookupflowvars {
public with sharing class Requests {
  @InvocableVariable(label='Records for Input' description='test' required=true)
  public string inputName;
  }


     @InvocableMethod(label='Update Person Member Reference' description='Update MemberReference field on Person')


    public static void UpdatePersonMemberReference(List<List<String>> personIds){

    List<String> values = new List<String>();
    for (List<String> subList : personIds) values.addAll(subList);
         // List<Id> oppids= new List<Id>(); 
        List<Opportunity> oppList = new List<Opportunity>();
        oppList = [select id,Name__c from opportunity where id in :values];
        for (Opportunity newopplist : oppList ){
        newopplist.Name__c =inputName';   //cannot access  inputName here!
        update newopplist;
        }

    }


}

Cannot access inputName

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

You can’t access it, because it’s in a different class. You need to pass in the request as a parameter:

public static void UpdatePersonMemberReference(List<Requests> people){

You should include the “personIds” as another InvocableParameter as well. Check the documentation for an example.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

Leave a Reply