function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nicholas ZuaroNicholas Zuaro 

Page redirect after flow issues.

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!
Andy BoettcherAndy Boettcher
Howdy!  If you're getting the error "controller=flowcontroller doesn't exist", you need to create that APEX class.  On the blog post - it's the second block of code that starts with "public class flowController{".
Nicholas ZuaroNicholas Zuaro
Hey Andy,

I just don't want you to think I'm ignoring or forgot about you. I havent been able to do anything with this yet.
Like I said, I'm very new to developer stuff so I'm still just trying to learn the ropes.
I didn't know that in order to create an Apex Class I had to do it in a Sandbox first, so I created a Sandbox and now i've been stuck waiting for it to refresh with all of the objects/flows/VF-Pages, etc. that I'll be needing to test with for what seems like a century.
So, thank you for the advice, I'll be getting back to you with my results as soon as I can have some!

-Nicholas Zuaro
Andy BoettcherAndy Boettcher
No worries!  Take your time, we're always here.  =)
Nicholas ZuaroNicholas Zuaro
Woohoo!
Thanks so much, Andy.
I can't wait to finally learn all of this.
And this Sandbox Refresh is crazy, the suspense is killing me!
Nicholas ZuaroNicholas Zuaro
Alright Andy, the Sandbox finally refreshed over the weekend!
So!
I attempted to create an Apex Class that looked like this:
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; }
 }
}

And it wouldn't let me save it because it says
Error: Compile Error: Variable does not exist: New_SalesOrder_ID at line 14 column 51

Which, when I go to the flow, the Variable clearly does exist, is being assigned in the correct place, and is of the Input & Output Type.
I don't see what's wrong so early on already?
Andy BoettcherAndy Boettcher
That's weird.  Try this for line 14:
strTemp = string.valueOf(flDemo.New_SalesOrder_ID);
Nicholas ZuaroNicholas Zuaro
Okay, so I did exactly that, and it accepted it. Then I created the Controller 
<apex:page Controller="flowController">
<flow:interview name="New_Sales_Order_From_Account_Page" interview="{!flDemo}" finishLocation="{!prFinishLocation}" />
</apex:page>

And that seemed to take as well. So I was about to go test it, but then I remembered that this needs to be an action/button on the Account Page and the flow needs to receive the variable of the account page the button was pressed from.
So I tried adding:
<apex:param name="vExistingAccount" value="{!Account.Id}"></apex:param>
to the controller above and it didn't take. It gave me this error:
User-added image
I don't know what that means exactly but I'm sure there's a better way to assign the variable now? Do I need to do that in the Apex Class created earlier?
& If so, where should it be? Should it still be like "<apex:param name="vExistingAccount" value="{!Account.Id}"></apex:param>" ??

Thanks again so much!!
 
Nicholas ZuaroNicholas Zuaro
:'(
Stephane Ott-HauvilleStephane Ott-Hauville
Hey there,
I was wondering if there were any updates on this issue? I have acheived a very similar redirect using the post from Andy but when deploying to production I have to build the test classes for this and I have no idea what to write in them. I am very new to Apex development and have read how to test triggers on new objects and such but in this flow redirect stuff... any help with the test class for this code discussed above would help! Thanks