How to navigate record detail page in flow

Hello everyone in this post let’s understand how to redirect a user to the record detail page using flow using Local Action. If you have not followed our previous blog please read here, How to send email using flow in Salesforce.

How to open a Record Page after finishing Flow?

Scenario: – create a contact record,  after creating navigate the user to the detail page of that record.

How to navigate the newly created record from a flow

  1. Create a Screen flow to accept input from users.
  2. Create a contact record.
  3. Call flow action.

Read the best salesforce Books: Click Here.

Let’s start with the implementation.

  1. Go to the object manager then search for flows.
  2. Click for a new flow to create a new one.
  3. Then Drag/Add screen interaction/element.
  4. Drag Name, Email, and Phone from component to screen.
  5. Add Api name to all dragged components.
  6. Add Api Name for screen: Create Contact Screen.
  7. Then click done.

Now let’s map these fields to create a contact record.

  1. Drag/Add create record interaction/element to the canvas.
  2. Then Map the fields to the correct contact fields.
  3. How Many Records to Create: One.
  4. How to Set the Record Fields: Use separate resources and literal values.
  5. Create a Record of This Object: Contact.
  6. Email: {!Email.value}.
  7. FirstName: {!Name.firstName}.
  8. LastName: {!Name.lastName}.
  9. MobilePhone: {!Phone.value}.
  10. Manually assign variables = true.

Next, we create a new resource that will store the id of a contact and then pass this id to the flow action. Let’s see how to create a new resource.

  • In Store Contact ID in Variable click for new resource.
  • Choose resource type as a variable.
  • Add API name : ContIds.
  • Data Type:  Text.
  • Then click done.

After creating a new resource type variable, choose the resource type in creating the record element as below.

  1. In-Store Contact ID in Variable: {!ContIds}.
  2. Then Click Done.

Now let’s create an action to navigate a user to the record detail page. To do that, we will create a new lightning component.

Go to the developer console, then create a new lightning component named DetailPageNavigation.

DetailPageNavigation.Cmp

<aura:component implements="force:lightningQuickAction,lightning:availableForFlowActions">
   <aura:attribute name="recordId" type="String" />
</aura:component>




DetailPageNavigation.Design

The recordId attribute is declared in the design resource so that it’s configurable in the local action.

<design:component>
   <design:attribute name="recordId" label="Record ID" />
</design:component>

DetailPageNavigation.Js

When the local action is executed, the flow calls the invoke method, which uses the force:navigateToSObject event to navigate to the created record.

({    invoke : function(component, event, helper) {
   // Get the record ID attribute
   var record = component.get("v.recordId");
   
   // Get the Lightning event that opens a record in a new tab
   var redirect = $A.get("e.force:navigateToSObject");
   
   // Pass the record ID to the event
   redirect.setParams({
      "recordId": record
   });
        
   // Open the record
   redirect.fire();
}})

Now we are done with our lightning component, so let’s connect a lightning component to flow action. To do that follow the below steps.

  1. In flow drag/Add action to the canvas.
  2. Then search for the lightning component created: DetailPageNavigation.
  3. Label: Navigate to the detail page of the record.
  4. In Set Input Values, Choose record id to: {!ContIds}.
  5. Then Click Done.




Congratulations now we are done with our flow, which will redirect a user to the detail page of the record. Let’s see how it looks.

Bonus: How to add Fault Path in Flow

Suppose your flow failed in the case of required fields or others, then how to show the error message in flow? To do that, you need to add fault errors in the flow. Let’s see how to create it.

In the contact record Lastname is the mandatory field, suppose you miss that field while creating a record, then we need to show the error message, then follow the below steps to create it.

  1. Click on Create Record interaction/element.
  2. Then click Add fault path.
  3. Then add screen interaction/element.
  4. From the component add display text.
  5. Add display text API name: Error_Msg_Screen.
  6. Then in Insert resource add: {!$Flow.FaultMessage}.
  7. Then choose the API name of the screen: Error_Screen.
  8. and click done.

Now you are done with the fault path, let’s check out how it looks completely.

Congratulations now we are completely done with our flow. If you find this blog helpful feel free to share it with your friends. If you have not followed our other blogs, feel free to check them out.

Output

Also Read

  1. Help And Training Community.
  2. Read the best salesforce Books: Click Here.
  3. HTTP Callout in Salesforce Flow Without Code [GET & POST]
  4. How to Invoke a Flow from a Lightning Web Component
  5. How to update child records using salesforce flow
  6. How to Assign records to Queue using Salesforce Flow?
  7. How to create a Data Table in Salesforce Flow : Complete Guide.
  8. How to retrieve record Type Id in flow
  9. How to navigate record detail page in flow
  10. How to send email using flow in salesforce
  11. How to Display Icon In Lightning Datatable
  12. How to Create Record in lightning Component
  13. How to Delete Multiple Records Using Checkbox In Lightning Component.

3 thoughts on “How to navigate record detail page in flow”

Leave a Comment