You need to sign in to do that
Don't have an account?
Stephane Ott-Hauville
How to build a test class for a visualforce page controller that references a flow?
Hello,
I am new to Apex and I built a page controller for a page that calls a flow and then grabs a variable from the flow to set a redirect page to that record (an Opportunity in this case). My problem is that I don't know how to write the test class for this code as I would need to reference the flow. The functionality works great but without the test class I can't move my changes to production. Any help is greatly appreciated.
The visualforce page code is this:
and the Apex Controller is this:
The flow that is referenced is a screen flow that simply looks up an Opportunity and saves it's ID in the flow variable varOppID.
I am new to Apex and I built a page controller for a page that calls a flow and then grabs a variable from the flow to set a redirect page to that record (an Opportunity in this case). My problem is that I don't know how to write the test class for this code as I would need to reference the flow. The functionality works great but without the test class I can't move my changes to production. Any help is greatly appreciated.
The visualforce page code is this:
<apex:page sidebar="false" Controller="OpportunityRedirect" > <flow:interview name="LookupReturnOpp" interview="{!LookupReturnOpp}" finishLocation="{!prFinishLocation}"> <apex:param name="varCurrentUserID" value="{!$User.Id}"/> </flow:interview> </apex:page>
and the Apex Controller is this:
public class OpportunityRedirect{ public String Account { get; set; } // Instanciate the Flow for use by the Controller - linked by VF "interview" attribute public Flow.Interview.LookupReturnOpp LookupReturnOpp {get;set;} // Factor your PageReference as a full GET/SET public PageReference prFinishLocation { get { PageReference prRef = new PageReference('/' + strOutputVariable); prRef.setRedirect(true); return prRef; } set { prFinishLocation = value; } } // Factor your Flow output variable pull as a full GET / SET public String strOutputVariable { get { String strTemp = ''; if(LookupReturnOpp != null) { strTemp = string.valueOf(LookupReturnOpp.getVariableValue('varOppID')); } return strTemp; } set { strOutputVariable = value; } } }
The flow that is referenced is a screen flow that simply looks up an Opportunity and saves it's ID in the flow variable varOppID.
If anyone has the same question, here is the test code. It currently only runs the code and not actually tests anything but I will edit it later. Thank you Jayant for your answer!
All Answers
If anyone has the same question, here is the test code. It currently only runs the code and not actually tests anything but I will edit it later. Thank you Jayant for your answer!