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
Anand Kumar 280Anand Kumar 280 

How to take record id while pressing a overiding button and take it to the component


I want to get the Id of the Parent From the related List View, as I have made aura CMP Which override
NEW button ,when  I press New button it redirect me different page , so component.get("v.recordId")
is UNDEFINED.
Best Answer chosen by Anand Kumar 280
Prateek Prasoon 25Prateek Prasoon 25
Hi, Anand 
Try Below Code,

 var pageRef = component.get("v.pageReference");
        var state = pageRef.state; // state holds any query params
        var base64Context = state.inContextOfRef;
        if (base64Context.startsWith("1\.")) {
            base64Context = base64Context.substring(2);
        }
        var addressableContext = JSON.parse(window.atob(base64Context));
        console.log("addressableContext.attributes.recordId",addressableContext.attributes.recordId);
        component.set("v.recordId", addressableContext.attributes.recordId);

All Answers

karthikeyan perumalkarthikeyan perumal
Hello Anand Kumar, 

Try this,

try defining force:recordData tage for main object. 
<force:recordData aura:id="caseRecord" recordId="{!v.recordId}" targetFields="{!v.Case}" layoutType="FULL"/>
 
<lightning:recordForm aura:id="ContactForm"
                        recordId="{!v.Case.ContactId}"
                        objectApiName="Contact"
                        fields="{!v.contactFields}"
                        columns="2"
                        mode="View"/>
define attribute for record Id
 
<aura:attribute name="recordId" type="Id"/>

for redirecting to another page use this tag:
 
var urlRedirect= $A.get("e.force:navigateToURL");
        urlRedirect.setParams({
            "url": "/upload&id=" + component.get("v.recordId")
        });
        urlRedirect.fire();

Thanks
karthik
 
Lauras gillLauras gill

While not quite as small or wieldy as those devices, Acer last year made ... The idea was to make a gaming laptop that's easy for a college ...Aka.ms/remoteconnect (https://akamsremoteconnect.info/)
Prateek Prasoon 25Prateek Prasoon 25
Hi, Anand 
Try Below Code,

 var pageRef = component.get("v.pageReference");
        var state = pageRef.state; // state holds any query params
        var base64Context = state.inContextOfRef;
        if (base64Context.startsWith("1\.")) {
            base64Context = base64Context.substring(2);
        }
        var addressableContext = JSON.parse(window.atob(base64Context));
        console.log("addressableContext.attributes.recordId",addressableContext.attributes.recordId);
        component.set("v.recordId", addressableContext.attributes.recordId);
This was selected as the best answer