Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Control a Flow’s Finish Behavior by Wrapping the Flow in a Custom Aura Component
By default, when a flow user clicks Finish, a new
interview starts and the user sees the first screen of the flow again. By embedding
a flow in a custom Aura component, you can shape what happens when the flow finishes
by using the onstatuschange action. To redirect
to another page, use one of the force:navigateTo* events such as force:navigateToObjectHome or force:navigateToUrl.
1<aura:component access="global">
2 <aura:handler name="init" value="{!this}" action="{!c.init}" />
3 <lightning:flow aura:id="flowData" onstatuschange="{!c.handleStatusChange}" />
4</aura:component>1// init function here
2handleStatusChange : function (component, event) {
3 if(event.getParam("status") === "FINISHED") {
4 // Redirect to another page in Salesforce, or
5 // Redirect to a page outside of Salesforce, or
6 // Show a toast, or...
7 }
8}Example
This function redirects the user to a case created in the flow by using the force:navigateToSObject event.
1handleStatusChange : function (component, event) {
2 if(event.getParam("status") === "FINISHED") {
3 var outputVariables = event.getParam("outputVariables");
4 var outputVar;
5 for(var i = 0; i < outputVariables.length; i++) {
6 outputVar = outputVariables[i];
7 if(outputVar.name === "redirect") {
8 var urlEvent = $A.get("e.force:navigateToSObject");
9 urlEvent.setParams({
10 "recordId": outputVar.value,
11 "isredirect": "true"
12 });
13 urlEvent.fire();
14 }
15 }
16 }
17}