How to access Custom Labels in Lightning Web Components (lwc)

Rate this post

What is a Custom Label?
Custom labels are text values stored in Salesforce that can be translated into any language that Salesforce supports. Use custom labels to create multilingual applications that present information (for example, help text or error messages) in a user’s native language.

To import Custom Labels we use @salesforce/label scope module in Lightning Web Components

Syntax

import labelName from '@salesforce/label/labelReference';

labelName  —> it is a name that refers to the label.labelReference —> The name of the label in your org in the format namespace.labelName
Note:
if you don’t have any namespace in your org use default namespace c
Ex: c.labelReference

Example

CustomLabelDemo.html

<template>
    <lightning-card  title="Custom Label Example" variant="narrow" icon-name="standard:opportunity">
        <p>{label.WelcomeLabel}</p>
    </lightning-card>
</template>

CustomLabelDemo.js

import { LightningElement } from 'lwc';

// importing Custom Label
import WelcomeLabel from '@salesforce/label/c.SalesforceCodeCrack';
export default class CustomLabelDemo extends LightningElement {
    label = {
        WelcomeLabel,
    };
}

CustomLabelDemo.js-meta.xml

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="CustomLabelDemo">
    <apiVersion>45.0</apiVersion>
    <isExposed>false</isExposed>
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
    </targets>
</LightningComponentBundle>

Result

Happy Learning!!!

Source : https://www.salesforcecodecrack.com/2019/01/how-to-access-custom-labels-in.html

8 Thoughts to “How to access Custom Labels in Lightning Web Components (lwc)”

  1. These are really great ideas in regarding blogging.
    You have touched some good factors here. Any way keep up wrinting.
    It is appropriate time to make some plans for the future and it
    is time to be happy. I have read this post
    and if I could I desire to suggest you some interesting things or suggestions.

    Maybe you could write next articles referring to this
    article. I desire to read even more things about it!
    It is the best time to make some plans for the longer term and
    it is time to be happy. I have read this post and
    if I may just I wish to counsel you few attention-grabbing things or tips.
    Perhaps you can write subsequent articles relating to this article.
    I desire to read more things approximately it! http://apple.com

  2. I am now not positive where you’re getting your
    info, but great topic. I needs to spend some time finding out much more
    or understanding more. Thanks for excellent info I was searching for this information for my mission.

  3. I go to see each day some websites and sites to read
    posts, except this weblog gives feature based content.

  4. I am not certain where you’re getting your information, however great topic.
    I must spend a while studying more or figuring out more.
    Thanks for excellent information I used to be in search of this info for my mission.

  5. This is the right webpage for everyone who wishes
    to understand this topic. You understand a whole lot its almost tough to argue with
    you (not that I really would want to…HaHa). You certainly
    put a new spin on a subject that’s been written about for decades.
    Excellent stuff, just great!

  6. It’s remarkable to pay a visit this website and reading the
    views of all friends regarding this post, while I am
    also zealous of getting know-how.

  7. Some times its a pain in the ass to read what blog owners wrote but this internet site is really user genial! .

  8. This piece of writing is in fact a pleasant one it helps new the
    web visitors, wwho are wishing for blogging.

Comments are closed.