force:hasSObjectName

Add the force:hasSObjectName interface to a Lightning component to enable the component to be assigned the API name of current record’s sObject type. The sObject name is useful if the component can be used with records of different sObject types, and needs to adapt to the specific type of the current record. This interface has no effect except when used within Lightning Experience, Salesforce1, 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.

This interface adds an attribute named sObjectName to your component. This attribute is of type String, and its value is the API name of an object, such as Account or myNamespace__myObject__c. For example:
<aura:attribute name="sObjectName" type="String" />
Note

Note

If your component implements force:hasSObjectName, you don’t need to add an sObjectName attribute to the component yourself. If you do add it, don’t change the access level or type of the attribute or the component will cause a runtime error.

The sObjectName attribute is set only when you place or invoke the component in a context of a record. For example, when you place the component on a record page, or invoke it as an action from a record page or object home. In all other cases, such as when you create this component programmatically inside another component, sObjectName isn’t set, and your component shouldn’t depend on it.

Example

This example shows the markup required to add the force:hasSObjectName interface to a Lightning component.

<aura:component implements="force:lightningQuickAction,force:hasSObjectName">

    <!-- ... -->
    
</aura:component>

The component’s controller can access the ID of the current record from the recordId attribute, using component.get("v.sObjectName"). The recordId attribute is automatically added to the component by the force:hasSObjectName interface.