• How To Access Custom Label In LWC

    Published By: Venu Gutta
    Published on: Sunday, 8 November 2020
    A- A+
    How To Access Custom Label In LWC


    How to get Custom Label value in LWC (Lightning Web Components):

    Usage of Custom Label: We know that we use custom label for error messages, constants and storing values which are translated into specific language by using translation workbench.

    How to access Custom Label in LWC components

    For accessing custom label value we need to import it from salesforce/label module. check below.
    import labelName from '@salesforce/label/labelApiName';

    Example: Accessing custom label in lightning web component

    Create custom label in your org. Add Hello_World as Name and "Hellow World! Welcome to salesforcepoint.com" as Value

    customLabelLwc.js
    import { LightningElement } from 'lwc';
    //importing custom label to 'WELCOME_MESSAGE'
    import WELCOME_MESSAGE from '@salesforce/label/c.Hello_World';
    
    export default class CustomLabelLwc extends LightningElement {
        message = WELCOME_MESSAGE; //assigning WELCOME_MESSAGE value to "message" property
    }


    customLabelLwc.html
    <template>
        <div class="slds-box slds-theme_shade slds-align_absolute-center">
            <h1>{message}</h1>
        </div>
    </template>

    Output:

    How To Access Custom Label In LWC example
  • No Comment to " How To Access Custom Label In LWC "