<apex:page Controller="ModemTroubleShootingCustomSimple" tabStyle="Case"> <flow:interview name="ModemTroubleShooting" interview="{!myflow}"/> <apex:outputText value="Default Case Prioriy: {!casePriority}"/> </apex:page>
public class ModemTroubleShootingCustomSimple { // You don't need to explicitly instantiate the Flow object; // the class constructor is invoked automatically public Flow.Interview.ModemTroubleShooting myflow { get; set; } public String casePriority; public String getCasePriority() { // Access flow variables as simple member variables with get/set methods if(myflow == null) return 'High'; else return myflow.vaCasePriority; } }
If you’re using a custom controller, you can also set the initial values of the variables at the beginning of the flow in the constructor of the flow. Passing in variables using the constructor is optional and isn’t necessary if you’re using <apex:param> tags to set the value.
public class ModemTroubleShootingCustomSetVariables { public Flow.Interview.ModemTroubleShooting myflow { get; set; } public ModemTroubleShootingCustomSetVariables() { Map<String, Object> myMap = new Map<String, Object>(); myMap.put('vaCaseNumber','123456'); myflow = new Flow.Interview.ModemTroubleShooting(myMap); } public String caseNumber { set; } public String getCaseNumber() { return myflow.vaCaseNumber; } }
You can use the getVariableValue method in the Flow.Interview class to enable a Visualforce controller to access the value of a flow variable. The variable may be in the flow embedded in the Visualforce page or in a separate flow that is called by a subflow element. The returned variable value comes from whichever flow the interview is currently 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.
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); } }
Flow | Apex |
---|---|
Text | String |
Number | Decimal |
Currency | Decimal |
Date | Date, DateTime |
Boolean | Boolean |
@isTest private class ModemTroubleShootingCustomSetVariablesTest { static testmethod void ModemTroubleShootingCustomSetVariablestests() { PageReference pageRef = Page.ModemTroubleShootingSetVariables; Test.setCurrentPage(pageRef); ModemTroubleShootingCustomSetVariables mytestController = new ModemTroubleShootingCustomSetVariables(); System.assertEquals(mytestController.getcaseNumber(), '01212212'); } }
By using the reRender attribute, the <flow:interview /> component re-renders the flow without refreshing the whole page:
<apex:page Controller="ModemTroubleShootingCustomSimple" tabStyle="Case"> <flow:interview name="ModemTroubleShooting" interview="{!myflow}" reRender="casePrioritySection"/> <apex:outputText id="casePrioritySection" value="Default Case Prioriy: {!casePriority}"/> </apex:page>