Redirect Flow in Lightning Experience

Redirect Flow in Lightning Experience

AppBuilder
In Lightning Experience there are two ways you can use Flows currently. You can use the beta Feature to drop a Flow into a Lightning Page using the App Builder.  There are some other limits including: lightningPage

  • Only able to pass the record ID into the Flow
  • No Redirect Option
  • Really limits you to only screen flows from a practicality stand point

Don’t get me wrong, this can still be a pretty cool thing with the right use Case. But what if you want to do a Redirect?

Back to good old Visualforce pages. These still will work with Lightning. This sample assumes you want to return to the starting record. So the scenario is you start on an Account Record, Click a button, Finish the flow and go back to the Account.

<apex:page standardController="Account">
    <flow:interview name="LIghtningTest" finishLocation="{!URLFOR('/'+Account.ID)}" />
</apex:page>

The URLFor Formula is the key here. You can also use this as a redirect to other records as long as you know the record id BEFORE the Flow starts. If you want to redirect to a record you created or did a lookup to get in the Flow, you need a controller extension.

Here’s a sample of the visualforce page

<flow:interview name="Universal_Redirect_Flow" finishLocation="{!redirectTo}" interview="{!redirectId}">

and the Apex Class
public class FlowRedirectController{	
	public Flow.Interview.Universal_Redirect_Flow redirectId {get; set;}
 	public String returnId;
	
    public PageReference getredirectTo(){ //This returns the page you want to go to
        system.debug(redirectId);
        if(redirectId != null) {
        	returnId = (string)redirectId.getVariableValue('vRedirectId'); //this gets the variable from the flow
        }  
    	PageReference send = new PageReference('/' + returnId);
    	send.setRedirect(true);
    	return send;
    }
}

 

Leave a Reply