In Automation, Blog, Flow, Salesforce Lightning, Tips & Tricks, Training & Certification

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 controller

<apex:page controller="FlowRedirectController">
<flow:interview name="Universal_Redirect_Flow" finishLocation="{!redirectTo}" interview="{!redirectId}">
</apex:page>
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;
    }
}

 

Recommended Posts
Showing 3 comments
  • Sumit Datta
    Reply

    Great Article, Brian

    This really helped me in learning FLow redirection for Lightning Experience.

    Regards

  • Néstor Velázquez
    Reply

    But, but, but, how do you make it using lightning

    I have this one:
    Compoment

    Controller
    init : function (component) {
    var flow = component.find(“flowData”);
    flow.startFlow(“myFlow”);
    }

    But when this finish do not made nothing, i need wich finish this redirect to my community page for registration.

    • Brian Kwong
      Reply

      It’s Lightning as in “Lightning Experience” it’s not for Lightning Components or Lightning Web Components.

      This is also a it of an outdated concept for redirecting withing Flow. Now we create Lightning Components to use as an Action. As long as the Flow is running in Lightning Runtime (with my domain enabled) it works. Check out https://unofficialsf.com/navigate-to-salesforce-record-sobject/ as an example.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.