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?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityYou 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.