Migrating Visualforce page to LWC:

Vf page code :

   <apex:pageBlockSectionItem >
            <apex:outputLabel value="{!$ObjectType.Account.fields.Discount_1__c.label}" for="CurrentAccountDiscount_1__c"/>
            <apex:outputLabel value="{!CurrentAccount.Discount_1__c}" />

{!CurrentAccount.Discount_1__c} - From Apex.

Tried below syntax in LWC:

   <lightning-formatted-rich-text label={$ObjectType.Account.fields.CDW__c.label} 

Label value isn't showing in User Interface. How to display value and Label LIKE Visualforce page, Trying to find almost equivalent tag in LWC.

Is there anyway to display Label and Value in a single Tag.

It Looks Like Below in VF Page:

Discount : 10


$ObjectType.Account.fields.CDW__c.label this sintax won't work in LWC.
You must reference a variable defined in your JS class. You could use getObjectInfo to retrieve information about SObject.


import ACCOUNT_OBJECT from '@salesforce/schema/Account';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';

@wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
getAccountInfo({ data, error }) {
    if (data) {
        this.discountLabel = data.fields.Discount_1__c.label;

Anyway lightning-formatted-rich-text doesn't have a label attribute, so you have to inline it and the field value using css. SLDS provides almost every class you need.


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