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

Control finishLocation using flow logic?

I'm designing some flows for which I'd like the finishLocation behavior to change depending on the path of the flow.  Depending what happens in the flow, I need users to end up at different pages when the flow is over.  Is there a way to do that without writing custom code?


YOu can control the finsih location of the flow


1) Embed the flow in a VF page

2) add control method to handle the finish location


VF page


<apex:page controller="LandscapingVisualFlowController" tabStyle="Account">

<flow:interview name="LandscapingQuestionnaire" finishLocation="{!EndPage}" interview="{!landscaping_interview}" buttonStyle="btn" >
<apex:param name="accid" assignTo="{!accid}" value="{!$CurrentPage.parameters.accid}"/>
<apex:param name="accName" assignTo="{!accName}" value="{!$CurrentPage.parameters.accName}"/>
<apex:param name="percentageComplete" value="10"/>
<apex:outputLabel value="{!landscaping_interview.percentagecomplete}"></apex:outputLabel>




public class LandscapingVisualFlowController {

String accountId;
public LandscapingVisualFlowController(){
System.debug('CONS '+ accountId);
public Flow.Interview.LandscapingQuestionnaire landscaping_interview {get;set;}

public PageReference getEndPage() {
System.debug('$$$$$$ ' + landscaping_interview);
PageReference pageRef = new Pagereference('/'+accountId);

return pageRef;



I am running into the same issue. The example provided in the previous post assumes that you are passing in an id to the visualforce page as a paremeter, then passes the id to the interview component, and uses that same id as the finish location. The id did not change in the flow. We want to be able to create a record in the flow and redirect the flow to the newly created record at finish. It sounds simple, but I have not found a way to do it. I also want to redirect to different pages depending on the path in the flow. If anyone knows how do do this, help would be appreciated.


I've tried the following: It doesn't work and I think it doesn't work because finishlocation is evaluated at the start of the flow, not the end.


1. Create a variable in the flow called finishlocation

2. Assign url of new record id to the finishlocation in the flow

3. Get the value of finishlocation in the controller and pass it to the visualforce page in the interview component as the finishlocation parameter.


public class FlowController{

public Flow.Interview.OpportunityFlow myFlow {get; set;}
public String recordId{get; set;}

public FlowController(ApexPages.StandardController sc){ recordid = sc.getrecord().id; } public pagereference getfinishlocation(){ return new pagereference('/' + myflow.finishlocation); } }



<apex:page Controller="flowcontroller" tabStyle="Case" >
<flow:interview name="MyFlow" interview="{!myflow}" finishlocation="{!finishlocation}"/>




Thanks for posting this follow-up.  I've been off for a few weeks so was unable to test this, but the situation you post is more or less exactly what I'd have been testing.  Disappointing that it doesn't work.


Anyone else have thoughts or suggestions?


A good post on stackoverflow here describes how this works. Look at the solution, it's surprisingly simple using the flow.interview variable


Unfortunately the Apex documentation hasn't kept pace re. how to use flow.interview


The essencial part is, creat your flow.interview.My_Flow_Name variable in the constructor. Create a finish location method, and in that method pick up the variable directly from your flow.interview.My_Flow_Name,




VF Page uses a typical tag like this



And the controller for the page


/* VF controller class */
public with sharing class myFlow_VFCx 
flow.interview.My_Flow_Name myFlow {get;set;}
public myFlow_VFCx(ApexPages.StandardController stdController)
     //Your logic in here
     //Pass value(s) TO the flow like this:
     Map<String, Object> valueMap = new Map<String, Object>();
     myFlow = new flow.interview.My_Flow_Name(valueMap);
public getFinishLocation()
     //GET Values from a flow like this
     return new PageReference('?'+myFlow.My_New_Contact_Id); //Where My_New_Contact_Id was a variable's unique name in the flow



Note the common confusion in using flow in apex is that the flow name is like a variable, it isn't - flows are stored as Meta data, like your custom objects, so when you are referring to My_Flow_Name you can think of it as if you are referring to an object.


I'm trying this, but I keep getting the error "System.FlowException: Interview not started" when I try to load the VF page and I don't understand why. Admittedly, I'm not the best at VF/Apex, so perhaps someone can clue me in. Am I missing a piece?



<apex:page Controller="RegWizControllerPub2" showHeader="false">
    <flow:interview name="Registration_Public" interview="{!myFlow}" finishLocation="{!finishLocation}"/>


public class RegWizControllerPub2 {

public Flow.Interview.Registration_Public myflow {get;set;}
public RegWizControllerPub2() {
    Map<String, Object> valueMap = new Map<String, Object>();
    if( Apexpages.currentPage().getParameters().get('staff') == 'true' ) valueMap.put('StaffEntry',true);
    myFlow = new flow.interview.Registration_Public(valueMap);
public PageReference getFinishLocation() {
    return new PageReference('/apex/RegMedForm?c=' + myflow.RegistrantContactID + '&e=' + myflow.EnrollmentID + '&t=' + myflow.RegistrationTypeName + + '&em=' + myflow.ConfirmationEmailAddress + '&gs=' + myflow.GuardianIDs + '&s=' + myflow.StaffEntry);




Perhaps just try running the flow wihtout the VF page to confirm it's configured ok to run. Then add the flow component on it's own and then add in each attribute to test their functionailty; ie. try (your instance)/flow/Registration_Public and then on the VF page start with just <flow:interview name="Registration_Public" /> and go from there.


The problem isn't with one specific thing in the flow. It works fine except when I try to reference a flow variable in the getFinishLocation method. I've structured my code just like MattEvans post previous to mine, and was hoping it would work that way, but it doesn't. If I reference any flow variable in the getFinishLocation() method, it gives me the error. This is the case even when I do this with the method:

public PageReference getFinishLocation() {
    if( myFlow == null) return null;
    else return new PageReference('/apex/RegMedForm?c=' + myflow.RegistrantContactID + '&e=' + myflow.EnrollmentID + '&t=' + myflow.RegistrationTypeName + + '&em=' + myflow.ConfirmationEmailAddress + '&gs=' + myflow.GuardianIDs + '&s=' + myflow.StaffEntry);

It seems like VF just doesn't like trying to reference a variable in the flow when it tries to load the page, but even if I tell it not to return anything when the flow is null it still has a problem, so I just don't know what the deal is. It's not null, but it also isn't "started" (error="System.FlowException: Interview not started")?



This is because the visualforce page will cycle through the finished location twice. So all you have to do is create a class Integer variable set to zero. And only debug your flow or use your flow variables if the Integer is greater than zero:


if(i > 0)
System.debug('FLOW !!!!!!!!!!!!!! ' + myFlow);


 Hope this helps.


@benderguy did you ever find a solution for this? I'm experiencing the same "Interview not started" issue when attempting to use a map to assign variable values back to the flow.


It's easy enough to grab the values from the flow, put passing values back to it is tricky.


Let me know if you have any ideas.




I have same problem any solve?


Unfortunately I had to give up on it. I didn't have the time to keep troubleshooting it. Too bad, because it seems like it would be pretty valuable, but I couldn't get it to work.


This ended up being the solution for myself:


I had the rerender attribute set to the rerender the flow each time the form was submitted and this was messing up the dynamic finish location. Once i removed the rerender attribute, the solution worked great for me. 


It is important to note that this solution requires a finish screen where the finish button is present.


Hope it helps.

Hi ,

Please create vf page like below:
<apex:page >
    <flow:interview name="Quick_Account" finishLocation="{!URLFOR('/003')}"></flow:interview>

and configure, "Name" and "FinishLocation" field.

Hope this helps!!!