Redirect to Standard Lightning Page with Record ID from Custom Lightning Component


In this article you will learn to redirect user to Standard Lightning Page with Record ID from Custom Lightning Component.

In my scenario the requirement was to override the Opportunity's New button with a Lightning Component and redirect user to Opportunity Standard page with a default record ID on the page load.

I tried it using Page Navigation but didn't get any success. So I tried below approach and the trick works 😃


Component

1
2
3
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,lightning:actionOverride,lightning:isUrlAddressable" access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>


Controller

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
({
	doInit : function(component, event, helper) {
        var rID = 'xxxxxxxxxxxxxxx';
        var createRecordEvent = $A.get("e.force:createRecord");
        createRecordEvent.setParams({
            "entityApiName": 'Opportunity',
            "recordTypeId": rID
        });
        createRecordEvent.fire();
  }
})

 


If you have any question please leave a comment below.
If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !

Thanks
Keep Coding 



Post a Comment

0 Comments