Newer Version Available

This content describes an older version of this product. View Latest

Set Flow Variable Values from a Visualforce Page

After you embed your flow in a Visualforce page, set the initial values of variables, record variables, collection variables, and record collection variables through the <apex:param> component.

You can set variables only at the beginning of an interview. The <apex:param> tags are evaluated only once, when the flow is launched.

You can set only variables that allow input access. If you reference a variable that doesn’t allow input access, attempts to set the variable are ignored. Compilation can fail for the Visualforce page, its <apex:page> component, or the Apex class.

Note

The following table lists the ways you can set a flow’s variable, record variable, and record collection variable values using Visualforce.

Method Variables Record Variables Collection Variables Record Collection Variables
Without a controller checkmark
With a standard controller checkmark checkmark
With a standard List controller checkmark
With a custom Apex controller checkmark checkmark checkmark checkmark
With an Interview Map checkmark checkmark checkmark checkmark

Setting Variable Values without a Controller

This example sets myVariable to the value 01010101 when the interview starts.

1<apex:page>
2    <flow:interview name="flowname">
3        <apex:param name="myVariable" value="01010101"/>
4    </flow:interview>
5</apex:page>

Setting Variable Values with a Standard Controller

You can use standard Visualforce controllers to set variables by passing in data from a record. This example sets the initial value of myVariable to the Visualforce expression {!account} when the interview starts.

1<apex:page standardController="Account" tabStyle="Account">
2    <flow:interview name="flowname">
3        <apex:param name="myVariable" value="{!account}"/>
4    </flow:interview>
5</apex:page>

Setting a Record Collection Variable Value with a Standard List Controller

Because record collection variables represent an array of values, you must use a standard list controller or a custom Apex controller. This example sets myCollection to the value of {!accounts} when the interview starts.

1<apex:page standardController="Account" tabStyle="Account" recordSetVar="accounts">
2    <flow:interview name="flowname">
3        <apex:param name="myCollection" value="{!accounts}"/>
4    </flow:interview>
5</apex:page>

Setting Variable Values with a Custom Apex Controller

For finer control over your Visualforce page than a standard controller allows, write a custom Apex controller that sets the variable value, and then reference that controller in your Visualforce page. This example uses Apex to set myVariable to a specific account’s Id when the interview starts.

1public class MyCustomController {
2    public Account apexVar {get; set;}
3
4    public MyCustomController() {
5        apexVar = [
6            SELECT Id, Name FROM Account
7            WHERE Name = 'Acme' LIMIT 1];
8    }
9}
1<apex:page controller="MyCustomController">
2    <flow:interview name="flowname">
3        <apex:param name="myVariable" value="{!apexVar}"/>
4    </flow:interview>
5</apex:page>

This example uses Apex to set a record collection variable myAccount to the Id and Name field values for every record with a Name of Acme.

1public class MyCustomController {
2    public Account[] myAccount { 
3        get {
4            return [ 
5                SELECT Id, Name FROM account 
6                WHERE Name = 'Acme'
7                ORDER BY Id
8            ] ;
9        }
10        set {
11            myAccount = value;
12        }
13    }
14    public MyCustomController () {
15    }
16}
1<apex:page id="p" controller="MyCustomController">
2    <flow:interview id="i" name="flowname">
3        <apex:param name="accountColl" value="{!myAccount}"/>
4    </flow:interview>
5</apex:page>

Setting Variable Values with an Interview Map

This example uses an Interview map to set the value for accVar to a specific account’s Id when the interview starts.

1public class MyCustomController {
2    public Flow.Interview.TestFlow myflow { get; set; }
3
4     public MyCustomController() {
5        Map<String, Object> myMap = new Map<String, Object>();
6        myMap.put('accVar', [SELECT Id FROM Account 
7                             WHERE Name = 'Acme' LIMIT 1]);
8        myflow = new Flow.Interview.ModemTroubleShooting(myMap);
9    }
10}
1<apex:page controller="MyCustomController">
2    <flow:interview name="flowname" interview="{!myflow}"/>
3</apex:page>

Here’s a similar example that sets the value for accVar to a new account when the interview starts.

1public class MyCustomController {
2    public Flow.Interview.TestFlow myflow { get; set; }
3
4     public MyCustomController() {
5        Map<String, List<Object>> myMap = new Map<String, List<Object>>();
6        myMap.put('accVar', new Account(name = 'Acme'));
7        myflow = new Flow.Interview.ModemTroubleShooting(myMap);
8    }
9}
1<apex:page controller="MyCustomController">
2    <flow:interview name="flowname" interview="{!myflow}"/>
3</apex:page>
This example uses a map to add two values to a string collection variable (stringCollVar) and two values to a number collection variable (numberCollVar).
1public class MyCustomController {
2    public Flow.Interview.flowname MyInterview { get; set; }
3
4    public MyCustomController() {
5        String[] value1 = new String[]{'First', 'Second'};
6        Double[] value2 = new Double[]{999.123456789, 666.123456789};
7        Map<String, Object> myMap = new Map<String, Object>();
8        myMap.put('stringCollVar', value1);
9        myMap.put('numberCollVar', value2);
10        MyInterview = new Flow.Interview.flowname(myMap);
11    }
12}
1<apex:page controller="MyCustomController">
2    <flow:interview name="flowname" interview="{!MyInterview}" />
3</apex:page>