Per the force:hasSObjectName interface documentation, I can reference an automatically added attribute named sObjectName to retrieve the object where my custom lightning component is being accessed. However when I try to use this value, it is undefined (code below):
Is this the correct way to reference the sObjectName? I'm aware I can pull this value from the record id, but I'd like to know what I'm doing wrong.
Lightning Component
<aura:component controller="lc_BuyerSellerSearchCriteriaCTRL" implements="force:hasSObjectName,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" description="lc_BuyerSellerSearchCriteriaDynamic" access="global" >
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<!--Component Code-->
</aura:component>
Component Controller
init: function(cmp, event, helper) {
console.log(cmp.get('v.sObjectName'));
}
This statement in the console log shows undefined
Best Answer
With a quick test I can confirm that this works fine as long as your component is within the right context. The same is mentioned in the documentation (emphasis mine).
You will need to verify that the component you have is placed within the correct record context.