[SalesForce] Communities Lightning – force:hasSObjectName doesn’t work, yet force:hasRecordId does

I'm in a single component. It implements the following:

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

In the init action:

doInit : function(component, event, helper) {
  console.log(component.get("v.sObjectName")); // undefined
  console.log(component.get("v.recordId")); // outputs record 
},

According to the official docs on both force:hasRecordId and force:hasSObjectName this should not be happening because the excluded contexts are exactly the same – but I'm getting return values for one and not the other? I've tried looking at object permissions…but they obviously wouldn't be able to load the record detail unless they can see the object.

These unsupported contexts include a few contexts that might seem like they should have access to the current record. Examples of these other contexts include the following:

Invoking the component from a global action (even when you’re on a record page)

Invoking the component from header or footer navigation in a community (even if the page shows a record)

This component is utilized internally on a Lightning Record Page as well as in the Community (I've tried placing it on various areas of the Custom_Object__c Record Detail page).

What's puzzling is force:hasSObjectName outputs correctly on the Lightning Record Page.

What am I missing? Is it because I'm using the Custom_Object__c Record Detail as opposed to the Shared Record Detail page? That seems silly…

Best Answer

It doesn't work in communities (forceCommunity:hasSObjectName interface does not exist in API 42.0)

You can pass the Id to the server and use the Apex Id.getSObjectType() method to discover the type that you can then pass back.