3

I'm creating a LWC that I want to have context from the currently focused tab. I want to have both the recordId and the sObjectName.

In fact, I've successfully done this for the recordId based on this answer - it basically involves wrapping the LWC in an Aura component and passing recordId into the LWC from the Aura component.

However, this does not appear to be working for sObjectName, which is another implicit "marker" property. It works when I add the testAura component to a page normally, but not when I add it to the utility bar.

Here's all my code:

testAura.cmp:

<aura:component implements="force:hasRecordId, force:hasSObjectName, flexipage:availableForAllPageTypes, force:lightningQuickAction, lightning:utilityItem" access="global">
    <c:testLwc recordId="{!v.recordId}" sObjectName="{!v.sObjectName}" />
</aura:component>

testAura.cmp-meta.xml

<?xml version="1.0" encoding="UTF-8" ?>
<AuraDefinitionBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>52.0</apiVersion>
    <description>Test Aura Component</description>
    <masterLabel>Test Aura Component</masterLabel>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
        <target>lightning__UtilityBar</target>
    </targets>
</AuraDefinitionBundle>

testLwc.html

<template>
    <div>recordId: <b>{recordId}</b></div>
    <div>sObjectName: <b>{sObjectName}</b></div>
</template>

testLwc.js

import { LightningElement, api } from 'lwc';

export default class TestLwc extends LightningElement {

    @api recordId;
    @api sObjectName;

    connectedCallback() {
        console.log('recordId:', this.recordId);
        console.log('sObjectName:', this.sObjectName);
    }

}

testLwc.js-meta.xml

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="KnowledgeSearch">
    <apiVersion>52.0</apiVersion>
    <isExposed>true</isExposed>
    <masterLabel>Test LWC</masterLabel>
    <description>Test LWC</description>
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
        <target>lightning__UtilityBar</target>
    </targets>
</LightningComponentBundle>

And here's a screenshot of the result:

enter image description here

1 Answer 1

2

The force:hasSObjectName is not supported in the utility bar context.

https://developer.salesforce.com/docs/component-library/bundle/force:hasSObjectName/documentation

So you would need to get the object name from the record id. You could call an Apex method that returns sobjectName based on record id.

For example

id recid = '0035e000008WyiAAAS';
system.debug(recid.getsObjectType());

You must log in to answer this question.

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