Let's say you are invoking an auto-launched flow from Apex using this simple syntax

Flow.Interview  flow = new Flow.Interview.myFlow(new map<String,Object> {'MyId'=> someId});

and the flow doesn't work, the Sobject lookup doesn't find the record despite passing in a valid ID. What could be the reason?

Adding to knowledge base as I didn't see this in the Apex doc although there is a relevant related documentation reference about URL parameter mapping to flow variables here.


The simple answer is the flow variable names are case sensitive.

When you use the Visual Flow editor to reference variables that you've created, the editor panels and dialogs will ensure you choose from existing variables and hence however you named your variables will be used in references to them. But when you are communicating from outside the flow such as in Apex, there is no tool support telling you what the variable names are and hence it is easy to run afoul of case sensitivity issues.

For example, imagine your flow uses a variable AccountID declared with an input property but your Apex code tries to pass in a map of AccountId => someId. Your flow will execute with a null value for its AccountID property. That is, AccountID is not AccountId. Coming from an Apex world where variable name references are not case sensitive, it is easy to lull yourself into a trap.

Here's a simple example

enter image description here

inVar (Input) and is assigned to outVar (Output) by the simple Assignment flow element.

This Apex class calls the flow twice, once with a matching-on-case variable name and once with a non-matching-on-case variable name

public class FlowInterviewExample {

    static map<String,Object> matchCaseOnInputArgName = new map<String,Object> 
                                                               {'inVar' => 'foo'};
    static map<String,Object> noMatchCaseOnInputArgName = new map<String,Object> 
                                                               {'INVAR' => 'foo'};

    public void doExample() {
        // Match case
        Flow.Interview  flow = new  Flow.Interview.Case_sensitivity_in_flow_interview(matchCaseOnInputArgName);

        //  Try no match on case
        flow = new  Flow.Interview.Case_sensitivity_in_flow_interview(noMatchCaseOnInputArgName);

and the results are:

USER_DEBUG [10]|INFO|foo // inVar value 'foo' assigned to outVar and picked up by apex
USER_DEBUG [15]|INFO|null // INVAR value 'foo' ignored by flow so outVar is null

Bottom line - use consistent variable names!

  • I've seen this before, too. Interesting that it's not documented anywhere. – sfdcfox Oct 24 '16 at 1:29

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.