Skip to main content

How to redirect to the newly created record from standard 'Create a Record' quick action button ?

 How to redirect to the newly created record from standard 'Create a Record' quick action button ?




In this blog we will see how we can navigate to New Record created from Standard 'Create a Record' Quick Action. 

Implementation and Use Case: 

Use Case:
We have a button Create Contact which is a 'Create a Record' quick Action on Account object record page and on click of which when the record is created we need to navigate to the new record created automatically. 

Implementation:
Create a Record Quick Action does creates the new record but it doesn't really navigate to the create record. It only shows us the success toast message that record is created.

Now since it is standard quick action we don't have anything to update or change right to make it navigate. So, as a work around we can make this happen by creating a new empty aura component. 

In this Aura Component we will use force:showToast event to fetch the new recordId and then use force:navigateToSObject to open the new record.

Step by step approach:
Step 1 : Go to Object Manager and open the Object where you need to add the Quick Action. 
        Example :- Account Object
Step 2 : Create the Quick Action and add the fields as per the requirement.
                  Note : Keep the Success Message field blank for this use case.
Step 3 : Add it to the record page layout where needed.        

Step 4 : Create the Aura component (See code below)
Step 5 : Add the Aura Component created in step 4 anywhere on the object flexipage. 



Note : - This component is a generic so you can add it to any flexipage where navigation is needed from the standard 'Create a Record' Quick Action.

Code Snippet-

redirectToNewRecord.cmp


<aura:component implements="flexipage:availableForAllPageTypes">
    <aura:handler event="force:showToast" action="{!c.redirectToNewRecord}"/>
</aura:component>

redirectToNewRecordController.js

({
    redirectToNewRecord : function(component, event, helper) {
        var data = event.getParam('messageTemplateData');
        console.log('data => '+data);
        if(!$A.util.isEmpty(data)){
            var execComp = data[1].executionComponent;
            console.log('execComp => '+execComp);
            if(!$A.util.isEmpty(execComp)){
                console.log('execComp.attributes => '+execComp.attributes);
                var recordId = execComp.attributes.recordId;
                var navEvent = $A.get("e.force:navigateToSObject");
                navEvent.setParams({
                    "recordId": recordId,
                    "slideDevName": "related"
                });                
                navEvent.fire();
            }            
        }      
    }
})


Demo :- 


You can learn more about the events from Salesforce Documents.

Resources: Salesforce Documents

Thank you all! 

#Keep Learning #Keep Sharing :) 

Recent blogs-

Comments

Popular posts from this blog

How to update Field Level Security in bulk ?

Assign Field Level Security(FLS) in Salesforce Demo:- In this blog we will see the easy way to update Field Level Security(FLS) for Permission sets/Profiles in bulk. I have created a tool to make the Admins job a little easier. Before jumping to tool let us see the different standard approach we follow to update FLS in Salesforce.                     As an admin we usually update FLS from salesforce setup/UI. If we are working on a new Application with many Permission sets and Objects with 100+ fields it can be very time consuming task. Using this tool we can assign FLS in just few mins. Let us take an example. Suppose we have a new application and we have created 20 Permission sets and 8 Profiles . Now there are 10 Objects in all and in each object we have 15 fields for which we need to update FLS for above Permission sets and Profiles. Let us first see the different approach to assign FLS in Salesforce. We have two ways in which we can update FLS for a particular field.  1 .To upd

How to create custom polymorphic field using LWC ?

How to create custom polymorphic field using LWC ? In this blog we will see how we can make polymorphic lookup field using LWC. What is Polymorphic field? A polymorphic field is one where related object might be one of the several different types of objects. There can be a use case where a customer wants to connect one object with multiple objects- i.e, relationships between objects or relate a child object to multiple parents's ojects. For example, in task Object we have three such polymorphic fields. The WhoId(Name) relationship of Task can be with Contact or a Lead. Assigned To field can be a User or a Queue. Similarly, a WhatId(Related To) relationship field of Task can be with many other objects like Accounts, Opportunities etc. In Salesforce, currently we do not have any OOTB option or may be we can say we do not have a datatype for polymorphic field which we can create but if required we can create a custom component to facilitate the same functionality. So let's get

How to use Hyperlink in Custom Toast Notification message using LWC

  Use Hyperlink in Custom Toast Notification message using LWC   We all know that a component can send a toast notification that pops up to alert users of a success, error, or warning. A toast can also simply provide information to the user. But what if we need a hyperlink on the message to navigate to the records on the message body. Yes, we can put Links as well on the message body as we can see in Standard Notification Toasts. This is very simple just we need to remember few things. We should know how to use Navigation Services by using NavigationMixin.GenerateUrl method. Let us see the functionality in this blog. To display a toast notification in Lightning Experience or Experience Builder sites we import ShowToastEvent from the lightning/platformShowToastEvent module. We use this ShowToastEvent to provide feedback to a user following an action, such as after a record is created. Now in this blog we will see how to add hyperlink in the message of the Show Toast event and navig