Override Standard New & Edit Button with Lightning Component

Are you working on a Lightning Component which you want to invoke on Standard Edit and New Button and want to know that from where it is being invoked then you are at the right place.

First of all, create a Lightning component with these interfaces

<aura:component implements="lightning:isUrlAddressable,force:hasRecordId,lightning:actionOverride">

Now go the Button & Action Section for the Object on which you want to override the button with a Lightning Component.

Click on the “New” or “Edit” standard button, and override them with the lightning component you just create.

Lightning Standard Button Override

Excellent, now whenever you click the New button for this Object, it will always show the component and not the standard record Creation form.

If you have Record Types on this object you should consider this option “Skip Record type selection page”, if you mark it true then it will not show the record type selection screen when you click the New button, otherwise it will show record Type Selection screen after the button is clicked and then you custom component.

How to know where the component is invoked from?

Notice that in the Lightning Experience, whenever you click on Edit or New button from any place be it List page, Related List and even Relation Tab in a New Page, the URL that is generated looks something like this.

We are interested in just one Variable in the URL which is inContextOfRef


Salesforce actually sends the base64 Encoded information to the fired component using this variable.

now in order to know what’s in this, you just need to remove the starting ‘1.’ from this variable and decode it in base64.

You can try decoding the string


here https://www.base64decode.org/

This is what you will see as the output based upon where you get parameter string.

1. If Clicked on New Button from Tab List


2. If Clicked on New Button from Related List on Account


3. If Clicked on New Button from Related Tab


To get this data just use the following code snippet.

  1. Add lightning:isUrlAddressable interface along with lightning:actionOverride interface in the Lightning component. Read more about this interface here.


<aura:component implements="lightning:isUrlAddressable,force:hasRecordId,lightning:actionOverride">
	<aura:attribute name="addressData" type="String"/>
	<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>


	doInit : function(component, event, helper) {
		var pageRef = component.get("v.pageReference");
		var state = pageRef.state;
		var base64Context = state.inContextOfRef;
		if (base64Context.startsWith("1\.")) {
			base64Context = base64Context.substring(2);
		var addressData = JSON.parse(window.atob(base64Context));

Perfect, now whenever you will click the New or Edit button, it will show the information of its source.

Standard button override component

Was this post useful? If yes then please share.

Comments (1)

  1. anneix says:

    thank you for this 🙂 Working fine for desktop.
    I do have some struggles using the above codes for mobile apps/browsers.
    In the controller, the value of the variable base64Context is undefined, thus throwing some errors.
    Can you advise what needs to be done? Thank you so much

Leave a Comment

All fields marked with an asterisk (*) are required