Request Quote

How To Use Custom Labels In Salesforce

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

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.

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.


Create Translations:

Open custom_label & click on ‘new’ under Translations.

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

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 Syntex 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 support@webkul.com

. . .

Comment

Add Your Comment

Be the first to comment.

css.php