2

Having come across documentation that states that flow variables can be retrieved for a specific flow in Apex, I tested this by writing the following code:

myEvent__e eventRecord = new myEvent__e(
    myBoolean__c = true,
    myText__c = 'my message'
);
Flow.Interview myFlowInterview = Flow.Interview.createInterview('myFlow',new Map<String, Object>{ 'platformEventRecord' => eventRecord });
myFlowInterview.start();
System.debug(myFlowInterview.getVariableValue('platformEventRecord'));

myFlow is an autolaunched flow with a myEvent__e-type record variable available for input called platformEventRecord. I expected eventRecord would be returned when I ran getVariableValue() but I got null instead despite the specified variable being in the flow. Is my code wrong or is getVariableValue() not meant to be used in such a case? I have a feeling it is the latter but is it the fact that I am passing a record that this isn't working? Is it something else? Considering the documentation states as follows,

getVariableValue(variableName) Returns the value of the specified flow variable. The flow variable can be in the flow embedded in the Visualforce page, or in a separate flow that is called by a subflow element.

does this mean this method only works if the flow and its subflow if present is embedded in a VF page?

4
  • 1
    is the variable available for output too? Apr 1 at 18:47
  • could be case sensitive issue
    – cropredy
    Apr 1 at 19:26
  • @cropredy I have confirmed the variable names are exactly the same.
    – user73893
    Apr 2 at 1:31
  • @CasparHarmer Your tip did the trick. When I made the variable available for output as well, I was able to get back the value that was passed in. Thanks!
    – user73893
    Apr 2 at 1:32
3

Make sure your flow variable is available for both output and input.

This is likely to fix your issue.

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.