Interview Class

The Flow.Interview class provides advanced Visualforce controller access to flows and the ability to start a flow.

Namespace

Flow

Usage

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..

Example

The following sample uses the getVariableValue method to obtain breadcrumb (navigation) information from the flow embedded in the Visualforce page. If that flow contains subflow elements, and each of the referenced flows also contains a vaBreadCrumb variable, the Visualforce page can provide users with breadcrumbs regardless of which flow the interview is running.
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 == nullreturn null;
      return (Double)(myFlow.getVariableValue('v1'));
   }

   public void start() {
      Map<StringObject> myMap = new Map<StringObject>();
      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>

Interview Methods

The following are instance methods for Interview.

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.

Signature

public Object getVariableValue(String variableName)

Parameters

variableName
Type: String
Specifies the unique name of the flow variable.

Return Value

Type: Object

Usage

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.

start()

Invokes an autolaunched flow or user provisioning flow.

Signature

public Void start()

Return Value

Type: Void

Usage

This method can be used only with flows that have one of these types.
  • Autolaunched Flow
  • User Provisioning Flow
For details, see “Flow Types” in the Visual Workflow Guide.

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.