Wednesday, 15 April 2020

Get Parent Record Id From Lightning URL



In component Create an attribute.

<aura:attribute name="recordId" type="String"/>


In Init method use the below code to get parent record Id from Related list.

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

reference : https://sfdclesson.com/2019/11/23/get-parent-record-id-from-lightning-url/


No comments:

Post a Comment