Newer Version Available
Interview Class
Namespace
Usage
SOQL and DML limits apply during flow execution. See Per-Transaction Flow Limits in the Salesforce Help.
- Create the object directly in your class by using:
- No namespace: Flow.Interview.flowName
- Namespace: Flow.Interview.namespace.flowName
- Create the object dynamically by using createInterview()
Examples: Starting Flow Interviews
- Whether the interview is created statically, with Flow.Interview.myFlow, or dynamically, with createInterview().
- Whether the flow is managed or local.
- Interview Created Statically for a Local Flow
-
1{ 2 Map<String, Object> inputs = new Map<String, Object>(); 3 inputs.put('AccountID', myAccount); 4 inputs.put('OpportunityID', myOppty); 5 6 Flow.Interview.Calculate_discounts myFlow = 7 new Flow.Interview.Calculate_discounts(inputs); 8 myFlow.start(); 9} - Interview Created Dynamically for a Local Flow
-
1public void callFlow(String flowName, Map <String, Object> inputs) { 2 Flow.Interview myFlow = Flow.Interview.createInterview(flowName, inputs); 3 myFlow.start(); 4} - Interview Created Statically for a Managed Flow
-
1{ 2 Map<String, Object> inputs = new Map<String, Object>(); 3 inputs.put('AccountID', myAccount); 4 inputs.put('OpportunityID', myOppty); 5 6 Flow.Interview.myNamespace.Calculate_discounts myFlow = 7 new Flow.Interview.myNamespace.Calculate_discounts(inputs); 8 myFlow.start(); 9} - Interview Created Dynamically for a Managed Flow
-
1public void callFlow(String namespace, String flowName, Map <String, Object> inputs) { 2 Flow.Interview myFlow = Flow.Interview.createInterview(namespace, flowName, inputs); 3 myFlow.start(); 4}
Example: Getting Variable Values
1public class SampleController {
2
3 //Instance of the flow
4 public Flow.Interview.Flow_Template_Gallery myFlow {get; set;}
5
6 public String getBreadCrumb() {
7 String aBreadCrumb;
8 if (myFlow==null) { return 'Home';}
9 else aBreadCrumb = (String) myFlow.getVariableValue('vaBreadCrumb');
10
11 return(aBreadCrumb==null ? 'Home': aBreadCrumb);
12
13 }
14}Interview Methods
The following are instance methods for Interview.
createInterview(namespace, flowName, inputVariables)
Signature
public static Flow.Interview createInterview(String namespace, String flowName, Map<String,ANY> inputVariables)
Parameters
Return Value
Type: Flow.Interview
Usage
Use this method to dynamically create a Flow.Interview object for the start() method.
- If the variable is cast to a specific flow, you can use myFlow.myVar to
access a variable, where myVar is the name of the variable.
1system.debug('My Output Variable: ' + myFlow.varName); - If the variable is of type Flow.Interview but not cast to a specific flow, you must
use getVariableValue() to access the flow's variables.
1system.debug('My Output Variable: ' + myFlow.getVariableValue('varName'));
If the flow doesn't exist in the current org, a TypeException is thrown.
createInterview(flowName, inputVariables)
Signature
public static Flow.Interview createInterview(String flowName, Map<String,Object> inputVariables)
Parameters
- flowName
- Type: String
- The flow’s API name.
- inputVariables
- Type: Map<String,Object>
- Initial values for the flow’s input variables.
Return Value
Type: Flow.Interview
Usage
Use this method to dynamically create a Flow.Interview object for the start() method.
- If the variable is cast to a specific flow, you can use myFlow.myVar to
access a variable, where myVar is the name of the variable.
1system.debug('My Output Variable: ' + myFlow.varName); - If the variable is of type Flow.Interview but not cast to a specific flow, you must
use getVariableValue() to access the flow's variables.
1system.debug('My Output Variable: ' + myFlow.getVariableValue('varName'));
If the flow doesn't exist in the current org, a TypeException is thrown.
getVariableValue(variableName)
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()
Signature
public Void start()
Return Value
Type: Void
Usage
- Autolaunched Flow
- User Provisioning Flow
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 a flow, the latest version is always run.