The following table lists the ways you can set a flow’s variable, sObject variable, and sObject collection variable values using Visualforce.
Method | Variables | sObject Variables | Collection Variables | sObject Collection Variables |
---|---|---|---|---|
Without a controller | ![]() |
|||
With a standard controller | ![]() |
![]() |
||
With a standard List controller | ![]() |
|||
With a custom Apex controller | ![]() |
![]() |
![]() |
![]() |
With an Interview Map | ![]() |
![]() |
![]() |
![]() |
This example sets myVariable to the value 01010101 when the interview starts.
<apex:page> <flow:interview name="flowname"> <apex:param name="myVariable" value="01010101"/> </flow:interview> </apex:page>
You can use standard Visualforce controllers to set variables or sObject 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.
<apex:page standardController="Account" tabStyle="Account"> <flow:interview name="flowname"> <apex:param name="myVariable" value="{!account}"/> </flow:interview> </apex:page>
Because sObject 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.
<apex:page standardController="Account" tabStyle="Account" recordSetVar="accounts"> <flow:interview name="flowname"> <apex:param name="myCollection" value="{!accounts}"/> </flow:interview> </apex:page>
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.
public class MyCustomController { public Account apexVar {get; set;} public MyCustomController() { apexVar = [ SELECT Id, Name FROM Account WHERE Name = ‘Acme’ LIMIT 1]; } }
<apex:page controller="MyCustomController"> <flow:interview name="flowname"> <apex:param name="myVariable" value="{!apexVar}"/> </flow:interview> </apex:page>
This example uses Apex to set an sObject collection variable myAccount to the Id and Name field values for every record with a Name of Acme.
public class MyCustomController { public Account[] myAccount { get { return [ SELECT Id, Name FROM account WHERE Name = 'Acme' ORDER BY Id ] ; } set { myAccount = value; } } public MyCustomController () { } }
<apex:page id="p" controller="MyCustomController"> <flow:interview id="i" name="flowname"> <apex:param name="accountColl" value="{!myAccount}"/> </flow:interview> </apex:page>
This example uses an Interview map to set the value for accVar to a specific account’s Id when the interview starts.
public class MyCustomController { public Flow.Interview.TestFlow myflow { get; set; } public MyCustomController() { Map<String, Object> myMap = new Map<String, Object>(); myMap.put('accVar', [SELECT Id FROM Account WHERE Name = 'Acme' LIMIT 1]); myflow = new Flow.Interview.ModemTroubleShooting(myMap); } }
<apex:page controller="MyCustomController"> <flow:interview name="flowname" interview="{!myflow}"/> </apex:page>
Here’s a similar example that sets the value for accVar to a new account when the interview starts.
public class MyCustomController { public Flow.Interview.TestFlow myflow { get; set; } public MyCustomController() { Map<String, List<Object>> myMap = new Map<String, List<Object>>(); myMap.put('accVar', new Account(name = 'Acme')); myflow = new Flow.Interview.ModemTroubleShooting(myMap); } }
<apex:page controller="MyCustomController"> <flow:interview name="flowname" interview="{!myflow}"/> </apex:page>
public class MyCustomController { public Flow.Interview.flowname MyInterview { get; set; } public MyCustomController() { String[] value1 = new String[]{'First', 'Second'}; Double[] value2 = new Double[]{999.123456789, 666.123456789}; Map<String, Object> myMap = new Map<String, Object>(); myMap.put('stringCollVar', value1); myMap.put('numberCollVar', value2); MyInterview = new Flow.Interview.flowname(myMap); } }
<apex:page controller="MyCustomController"> <flow:interview name="flowname" interview="{!MyInterview}" /> </apex:page>