function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Henry MichelHenry Michel 

I have to override the standard new button.

I have an overridden standard 'New' button in lightning with my custom component but when I am using it from the related list of the parent object, I am not getting parent record id in the URL. Also, 'hasRecordId' is giving Id of the child record only. Any Solution for this??
Best Answer chosen by Henry Michel
Ajay K DubediAjay K Dubedi
Hi Henry,

Firstly, you need to implement 'lightning:isUrlAddressable' in your component and then use below piece of code according to your requirement.
Also, go to the below link to know more about 'lightning:isUrlAddressable':

https://developer.salesforce.com/docs/component-library/bundle/lightning:isUrlAddressable/documentation

var ref = c.get("v.pageReference");
var state = ref.state; 
var context = state.inContextOfRef;
if (context.startsWith("1\.")) {
context = context.substring(2);
var addressableContext = JSON.parse(window.atob(context));
console.log('addressableContext----->'+JSON.stringify(addressableContext));   // you can get your recordId and other things here.
}


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com  

All Answers

Ajay K DubediAjay K Dubedi
Hi Henry,

Firstly, you need to implement 'lightning:isUrlAddressable' in your component and then use below piece of code according to your requirement.
Also, go to the below link to know more about 'lightning:isUrlAddressable':

https://developer.salesforce.com/docs/component-library/bundle/lightning:isUrlAddressable/documentation

var ref = c.get("v.pageReference");
var state = ref.state; 
var context = state.inContextOfRef;
if (context.startsWith("1\.")) {
context = context.substring(2);
var addressableContext = JSON.parse(window.atob(context));
console.log('addressableContext----->'+JSON.stringify(addressableContext));   // you can get your recordId and other things here.
}


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com  
This was selected as the best answer
Victor GatnickiVictor Gatnicki
The above answer does not work for mobile view because the mobile view does not have inContextRef paramater in the URL
moses mano 3moses mano 3
Hi Henry,

I'm also trying to imlement the similar functionlity. but when i click new button in related list, It opens a new tab and displaying a popup window. But I'm not able to close that tab. can you please let me know if you have face this issue or help me in resolving this. 
User-added image

Thank,
Mano