TransWikia.com

Fetch Field Label in Lightning Web Components

Salesforce Asked by Pranay Jaiswal on November 5, 2021

I am using uiRecordApi to fetch record from the database, to provide static binding I am using fields using schema.

import  MAX_LTV from '@salesforce/schema/Opportunity.Max_LTV__c';

All works, but am not able to fetch the Label of the field, printing MAX_LTV only gives API Name.

{fieldApiName: "Max_LTV__c", objectApiName: "Opportunity"}

The reason being, now I have records and fields, but not label to dynamically iterate and display on-screen using template-for,

is there a way or I have to use apex for it?

One Answer

You will get the labels of all fields in getObjectInfo. You should use data.fields.fieldName.label

Below is the sample code to get label of CloseDate field in Opportunity.

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

export default class Poc extends LightningElement {

    @wire(getObjectInfo, { objectApiName: OPPORTUNITY_OBJECT })
    oppInfo({ data, error }) {
        if (data) console.log('CloseDate Label => ', data.fields.CloseDate.label);
    }

}

Answered by salesforce-sas on November 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP