2

Let us suppose that I go to a record. Then I am editing its page by adding a custom component on the page.

Now I would like to be able to get a record id in the custom component which was added to the page. How can I do that?

1 Answer 1

5

You implement the force:hasRecordId interface on your component:

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">

From there, you can get the ID at any point:

doInit: function(component, event, helper) {
  var recordId = component.get("v.recordId");
  // ...

Do not put your own attribute called recordId in to your component; it is defined by the force:hasRecordId interface for you automatically. You can read more in this developer blog post and in the documentation.

3
  • Can you also show us how to do it in the lightning web component (none aura component) please? or post a reference link that shows it? Thanks!
    – Bahman.A
    Apr 16, 2021 at 15:05
  • 1
    @Bahman.A See this for the LWC version.
    – sfdcfox
    Apr 16, 2021 at 15:44
  • Thank you so much for the quick response. You ROCK!!
    – Bahman.A
    Apr 16, 2021 at 15:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .