1

I have an action on Contact page which opens a lightning component. How do I pass the current Contact record id to the lightning component?

4

You can refer to the documentation here

basically, you have implement the force:hasRecordId attribute:

<aura:component controller="yourControllerifany"
implements="force:hasRecordId">

declare it in your component:

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

and in your client side controller, you should be able to fetch the record ID:

"recordId": component.get("v.recordId")

further documentation on using actions and recordid's can be found here

  • 1
    No need to declare an aura:attribute separately, if force:hasRecordId is implemented <aura:attribute name="recordId" type="Id" /> is inherited automatically – Praveen Apr 11 '17 at 18:54
  • I see, Good to know! i just noticed it is mentioned in the second documentation link I referred, however, the salesforce doc includes Both, the aura attribute and the force:recordId in the code snippet examples. – glls Apr 11 '17 at 18:58
0

The best Possible workaround:

Component:

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

Controller:

({
    doInit : function(component, event, helper) {
        var pageRef = component.get("v.pageReference");
        var state = pageRef.state; // state holds any query params
        var base64Context = state.inContextOfRef;
        /*
            *For some reason, the string starts with "1.", if somebody knows why,
            *this solution could be better generalized.
        */
         if (base64Context.startsWith("1\.")) {
            base64Context = base64Context.substring(2);
        }
        var addressableContext = JSON.parse(window.atob(base64Context));
        component.set("v.recordId", addressableContext.attributes.recordId);
})

It is because of the context is changing when you overridden the standard button.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.