Play Games

Search This Blog

Monday, April 22, 2024

How to access custom labels in lightning web component salesforce - Salesforce Globe 4u

 Solution: 

Step1: Import the label in LWC using the below import 

import labelname from "@salesforce/label/labelreference";

Step2: create label object as below 

label ={

        myblogURL

    }

Reference the custom label in html file using label.labelname.

Example:



customLabelInLWC.html:

<template>

    <lightning-card>

        <h1> Custom Label value :{label.myblogURL}</h1>

    </lightning-card>

</template>

customLabelInLWC.js:

import { LightningElement } from 'lwc';

import myblogURL from "@salesforce/label/c.Blog_URL";

export default class CustomLabelInLWC extends LightningElement {

    label ={

        myblogURL

    }

}

customLabelInLWC.js-meta.xml:

<?xml version="1.0" encoding="UTF-8"?>

<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">

    <apiVersion>59.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__RecordPage</target>

        <target>lightning__AppPage</target>

        <target>lightning__HomePage</target>

    </targets>

</LightningComponentBundle>

Output:



No comments:

Post a Comment