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?


You can refer to the documentation here

basically, you have implement the force:hasRecordId attribute:

<aura:component controller="yourControllerifany"

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

  • 2
    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

The best Possible workaround:


    <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}"/>


    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 agree to our terms of service, privacy policy and cookie policy

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