How to use Custom Labels in LWC (Lightning Web Components)

Webner Solutions
2 min readSep 30, 2021

--

How to use Custom Labels in LWC (Lightning Web Components)
How to use Custom Labels in LWC (Lightning Web Components)

Custom Labels are text values that can be translated into any language that salesforce supports. We can use custom labels to represent help text or error messages to the users in their native language. Custom labels can be fetched from apex class, visualforce pages, aura components, and LWC (Lightning Web Components).

Create a custom label:

  1. Go to setup, search for a custom label in the quick find box and select it.
  2. Create a custom label by clicking on the “New Custom Label” button and the following window will be opened:
  1. Enter a value for the Description, Name, and Value field in the above screenshot and click on the save button, the label will be saved.

Use Custom Labels in LWC:

  1. Import custom labels in component’s javascript file:
  2. Here is the sample code of the javascript file of LWC(customLabel.js):
    import { LightningElement } from 'lwc';
    // importing Custom Label
    import webnerLogo from '@salesforce/label/Webner_Logo_Description; //Org without namespace
    export default class CustomLabel extends LightningElement {
    webnerLogoLabel = webnerLogo;
    }

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Originally published at https://blog.webnersolutions.com on September 30, 2021.

--

--

Webner Solutions
Webner Solutions

Written by Webner Solutions

Our team in Salesforce is very strong, with in-depth knowledge of Salesforce classic and Lightning development as well as the Service cloud.

No responses yet