6

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...

2
  • Looks like your component is in a global context , sObjectName value is tightly coupled to record Layouts, like a homepage record layout or record detail layout etc , this is one particular reason why force:hasSobjectName would not work when you create the component dynamically or use it as a global quick-action. There is no record layout tied to that marker interface.
    – Sumuga
    Nov 2, 2017 at 8:52
  • Correct there is no record layout tied to my component, but it's placed in the body of the Record Detail in Communities... that should be sufficient by the documentation standards (it's getting recordId after all). My current workaround is to just init a custom data map of my required settings and get my own sObjectName sadly.
    – tsalb
    Nov 2, 2017 at 17:12

1 Answer 1

3

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .