8

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?

1 Answer 1

19

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);
    }

}
1
  • 1
    That's what I wanted. Thanks :) Sep 12, 2019 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.