Get Record Id In Aura Component

by Zuber Rangreaz

Hello friends, today we are going to discuss Get Record Id In Aura Component. To retrieve the record ID in a Lightning Aura Component, you can utilize the force:hasRecordId interface. This interface allows your component to be assigned the ID of the current record. Here’s how you can implement it:

Also, check this: Get Record Id in LWC

Key Highlights :

  1. In your Aura component, include the force:hasRecordId interface. This enables your component to access the current record’s ID.
  2. Simplified Development: Aura components offer an innate method for accessing the record Id, streamlining development without intricate setups.
  3. Flexibility in Customization: Developers can tailor component behavior based on the viewed record, ensuring personalized and engaging user interactions.
  4. Heightened Productivity: Eliminate the need for manual record Id retrieval, allowing developers to focus on feature-rich application development.

Code :

GetRecordIdInAuraComponent.html

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global">
     <aura:attribute name="recordId" type="String" />
    <lightning:card title="Record Id Example" iconName="standard:activation_target">
        <div class="slds-m-around_medium">
            <p>Record Id: {!v.recordId}</p>
        </div>
    </lightning:card>
</aura:component>

GetRecordIdInAuraComponent.js

({
    doInit : function(component, event, helper) {
        var recordId = component.get("v.recordId");
        console.log("Record Id: ", recordId);
    }
})

Output :

Reference :

  1. Has Record Id
What’s your Reaction?
+1
1
+1
0
+1
0
+1
0
+1
0
+1
0

You may also like

Leave a Comment