Newer Version Available

This content describes an older version of this product. View Latest

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.

To control a flow’s finish behavior at design time, make your custom Aura component available as a flow action by using the lightning:availableForFlowActions interface. To control what happens when an autolaunched flow finishes, check for the FINISHED_SCREEN status.

Tip

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}