Back to Top

How To Use Custom Labels In Salesforce

Updated 21 October 2019

Custom labels are custom text values, which can be called from apex classes, visual force pages or lightning components. To support multilingual feature in an application, we can use custom labels that offer user’s to change/translate text values into any language that supported by salesforce. It helps to provide the best user experience that offers application in the user’s native language.

Required Editions:

Developer, Professional, Enterprise, Performance, and Unlimited Editions (both Salesforce Classic and Lightning Experience).

User Permissions Needed
Create, edit, or delete custom labels: Customize Application
Create or override a translation: Manage Translation

OR

Searching for an experienced
Salesforce Company ?
Find out More

View Setup and Configuration and be designated as a translator


Create a custom label:

Click on Setup –> Build –> Create –> Custom Label

In the custom labels, click ‘New Custom Label’ to create a new one.

new custom label

In ‘New Custom Label’, Enter the label description, categories(Text entered in this field can be used in filter criteria when creating Custom Label list views), mark the component as protected and value which is used to represent whenever this custom label is called upon in Apex, Visualforce or Lightning pages.

new custom label data filling
Create Translations:

Open custom_label & click on ‘new’ under Translations.

new translations

Under ‘New Translation’, select your language & fill text that you want to show.

Fill new translations

Save It.

Note: Translation workbench should be enabled & Your org must have some enabled language.

Whenever this selected language is called upon using language code and custom label in Apex, Visualforce or Lightning page it shows the text which we provided in custom label translation text.

Apex Syntax for Custom Label:

System.Label.Labelname

Visualforce Syntax for Custom Label:

{!$Label.Label_name}

Lightning Syntax for Custom Label:

Use the following syntax to access custom labels in Lightning components(.cmp and .app resources only).

  • {!$Label.c.labelName} for the default namespace
  • {$Label.namespace.labelName} if your org has a namespace, or to access a label in a managed package

Label in JavaScript code if your org has a namespace.

  • $A.get($Label.c.labelName) for the default namespace
  • $A.get($Label.namespace.labelName) if your org has a namespace, or to access a label in a managed package

Note: You can create up to 5,000 custom labels for your organization, and they can be up to 1,000 characters in length. Custom labels from managed packages don’t count toward this limit.

For any query please comment below or write us to [email protected]

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


1 comments

  • kimmy kervel
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home