The Flow.Interview class is used with Visual Workflow. Use the methods in this class to invoke an autolaunched flow or to enable a Visualforce controller to access a flow variable..
public class SampleController { //Instance of the flow public Flow.Interview.Flow_Template_Gallery myFlow {get; set;} public String getBreadCrumb() { String aBreadCrumb; if (myFlow==null) { return 'Home';} else aBreadCrumb = (String) myFlow.getVariableValue('vaBreadCrumb'); return(aBreadCrumb==null ? 'Home': aBreadCrumb); } }
The following includes a sample controller that starts a flow and the corresponding Visualforce page. The Visualforce page contains an input box and a start button. When the user enters a number in the input box and clicks Start, the controller’s start method is called. The button saves the user-entered value to the flow’s input variable and launches the flow using the start method. The flow doubles the value of input and assigns it to the output variable, and the output label displays the value for output by using the getVariableValue method.
public class FlowController { //Instance of the Flow public Flow.Interview.doubler myFlow {get; set;} public Double value {get; set;} public Double getOutput() { if (myFlow == null) return null; return (Double)(myFlow.getVariableValue('v1')); } public void start() { Map<String, Object> myMap = new Map<String, Object>(); myMap.put('v1', input); myFlow = new Flow.Interview.doubler(myMap); myFlow.start(); } }
The following is the Visualforce page that uses the sample flow controller.
<apex:page controller="FlowController"> <apex:outputLabel id="text">v1 = {!output}</apex:outputLabel> <apex:form > value : <apex:inputText value="{!output}"/> <apex:commandButton action="{!start}" value="Start" reRender="text"/> </apex:form> </apex:page>
The following are instance methods for Interview.
public Object getVariableValue(String variableName)
Type: Object
The returned variable value comes from whichever flow the interview is running. If the specified variable can’t be found in that flow, the method returns null.
This method checks for the existence of the variable at run time only, not at compile time.
public Void start()
Type: Void
When a flow user invokes an autolaunched flow, the active flow version is run. If there’s no active version, the latest version is run. When a flow admin invokes an autolaunched flow, the latest version is always run.