12

Is there any way to get Object label from API Name? I tried Below, but it gives API Name Only

import objectName from '@salesforce/schema/object';

1 Answer 1

19

Salesforce should provide easy way to get the standard object labels without necessarily using ui api.

With UI api one can get the label as below

<template>
    <lightning-card title={objectInfo.data.label} icon-name="standard:account">
    </lightning-card>
</template>

JS file

import { LightningElement, wire, api, track } from 'lwc';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';

export default class ObjectLabel extends LightningElement {
    @api objectApiName;
    @track objectInfo;
    @wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
    objectInfo;
}

The other alternative would be to write an apex class that can return the object label taking object api name as parameter and then use @wire service to display on lwc frontend .

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.