• Stephane Ott-Hauville
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
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:
<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.
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:
<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.
Hello,
I'd like to preface this with the fact that I'm incredibly new to Salesforce Development and most coding in general, actually. So please bear with me.
Ok, 
I'm trying to create a handy little time-saving flow-powered button to help people create a New Sales Order as quickly as possible.
So the button is located on the Account page, so this way, it already has all of the accounts information to enter into the Sales Order. So basically, the flow looks up the account, Creates a Sales Order, and then is finished. 
Initially I wanted the user to be redirected to the Sales Order they just created.

Initially, I had a functioning controller that looked like this:
<apex:page standardController="Account"> 

    <flow:interview name="New_Sales_Order_From_Account_Page" 

    <apex:param name="vExistingAccount" value="{!Account.Id}"></apex:param>

    </flow:interview>

​</apex:page>

Then, before seeing your post, I tried to do something like this:
<apex:page standardController="Account"> 

    <flow:interview name="New_Sales_Order_From_Account_Page" 
        finishLocation="{!URLFOR('/' + Account.ID)}">
    <apex:param name="vExistingAccount" value="{!Account.Id}"></apex:param>
        <apex:param name="New_SalesOrder_ID" 
            value="{!$CurrentPage.parameters.New_SalesOrder_ID}" />
    </flow:interview>

​</apex:page>
Which I believe to have turned out to be a disaster.
Then, after seeing your post, I tried this:
<apex:page controller="flowController">
<flow:interview name="New_Sales_Order_From_Account_Page" interview="{!flDemo}" finishLocation="{!prFinishLocation}" />

public class flowController{
public Flow.Interview.New_Sales_Order_From_Account_Page flDemo {get;set;}
public PageReference prFinishLocation {
 get {
PageReference prRef = new PageReference('/' + strOutputVariable); prRef.setRedirect(true);
 return prRef;
 }
 set { prFinishLocation = value; }
 }
public String strOutputVariable {
 get {
 String strTemp = '';
 if(flDemo != null) {
 strTemp = string.valueOf(flDemo.getVariableValue(New_SalesOrder_ID));
 }
 return strTemp;
 }
 set { strOutputVariable = value; }
 }
}
</apex:page>

Which failed so miserably, I couldn't even save it. (Pretty sure my first error was something along the lines of "controller="flowController" doesn't exist."
Is the controller and then this other set of code supposed to be two different pages? or one in the same?
I'd like to reiterate how new I am to all of this, but I'm trying to learn by working off of and disecting good examples like these!
Thanks so much for your help!