Anyone who has worked on Screen flow specifically for cross object flows knows that Salesforce default functionality does not redirect users from flow to the created or updated record. Therefore the user will require to manually search for that created/updated record and look for that created record to view the details. This is not the ideal user experience that your user would want especially in fast-moving environments. It can impact your user’s productivity as well as increase the probability of human errors.

In this tutorial, we will look at how you can write a very simple lightning component and reuse that for all flows in your org to redirect the user to the record page after they finish the flow. No apex class/controller is used for this component so no test class is required either.

Let’s start with creating a Simple cross object flow first as shown below

Cross object Screen flow

Get Account Record

Add following fields on the screen component

Subject
Name

Add Create record component

Add field value within component as shown in the screen shot below

Create new lightning component from developer console

Create New Lightning Component from developer console
Add Lightning Component name as well as select all check boxes in the above screen since we will be using this component in multiple areas.

Add following code to your component

Make sure to include ” lightning:availableForFlowScreens ” class as implements (Highlighted in the screenshot below)to make this component available for flow.

Component

<aura:component implements="lightning:availableForFlowScreens" access="global" >
<aura:attribute name="recId" type="String" />
<aura:handler name="init" value="{!this}" action="{!c.init}" />
</aura:component>

Controller

({
init : function(component, event, helper) {
$A.get("e.force:navigateToSObject").setParams({
"recordId": component.get("v.recId"),
"slideDevName": "related"
}).fire();
}
})

Design

<design:component>
<design:attribute name="recId" label="Id of the record" />
</design:component>

Modify screen flow to include flow redirect component

Make following changes to the previously created flow to include this lightning component and navigate user to the created record

1.Modify “Create record” on flow to store record id of newly created case

Create new text variable called “NewCaseId” and check the checkbox to make that available for output

2. Add new Screen component on the flow

Insert new screen component after create record on the flow. And pass NewCaseId to the lightning component for the redirect as shown in the screenshot below

3. Save and Activate the Flow

User will now be automatically redirected/Navigated to the created record after flow finish creating the record.

For more Tips and tricks like this please click here or Flow Menu item. Follow my YouTube channel for more videos on this topic.