Newer Version Available
force:hasRecordId
Add the force:hasRecordId
interface to a Lightning component to
enable the component to be assigned the ID of the current record. The current record ID is
useful if the component is used on a Lightning record page, as an object-specific custom
action or action override in Lightning Experience or the Salesforce app, and
so on.
This interface has no effect except when used
within Lightning Experience, Salesforce app,
and template-based communities.
This interface is a marker interface. A marker interface is a signal to the component’s container to add the interface’s behavior to the component. You don’t need to implement any specific methods or attributes in your component, you simply add the interface name to the component’s implements attribute.
The force:hasRecordId
interface does two things to a component that implements it.
- It adds an attribute named recordId to your
component. This attribute is of type String, and its value is an 18-character Salesforce
record ID, for example: 001xx000003DGSWAA4. If you added it yourself, the attribute
definition would look like the following
markup:
1<aura:attribute name="recordId" type="String" /> - When your component is invoked in a record context in Lightning Experience or the Salesforce app, the recordId is set to the ID of the record being viewed.
Example
This example shows the markup required to add the force:hasRecordId interface to a Lightning component.
1<aura:component implements="force:lightningQuickAction,force:hasRecordId">
2
3 <!-- ... -->
4
5</aura:component>The component’s controller can access the ID of the current record from the recordId attribute, using component.get("v.recordId"). The recordId attribute is automatically added to the component by the force:hasRecordId interface.