Newer Version Available
Interview Class
Namespace
Usage
SOQL and DML limits apply during flow execution. See Per-Transaction Flow Limits in Salesforce Help.
To create an Interview object, you have two options.
- 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()
To enforce sharing rules, run the flow or Apex on API version 62.0 or later. The Apex class must be declared using the with sharing keyword. The flow runs more securely in the default context when an Apex class that’s declared using the with sharing keyword launches an autolaunched flow. The flow enforces the sharing rules of the user that executes the Apex class. Data access is restricted to the sharing rules of the user that executed the Apex class. For example, a query can return fewer rows than it did in system context without sharing. An operation can fail because the user doesn’t have the correct permissions.
Examples: Starting Flow Interviews
These examples are all sample controllers that start an interview for the flow from the Build a Discount Calculator project on Trailhead. Each shows a different permutation, based on:
- 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
Interview Created Dynamically for a Local Flow
Interview Created Statically for a Managed Flow
Interview Created Dynamically for a Managed Flow
Example: Getting Variable Values
Interview Methods
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.
How you get output variable values from an interview depends on the type of the Apex variable where you're storing the interview.
- 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.
- 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.
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.
How you get output variable values from an interview depends on the type of the Apex variable where you're storing the interview.
- 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.
- 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.
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 runs. If there’s no active version, the latest version runs. When a flow admin invokes a flow, the latest version always runs.