Custom Label Tutorial In Salesforce With Examples – Apex Developer Guide

Hello, Friends, I am very happy to tell you all with this useful information. This post is only for Beginners. And for the experienced persons, this post helps them to refresh the things which they already know.

What is the custom label?

Custom Labels are custom text values, up to 1,000 characters, that can be accessed from Apex Classes or Visualforce Pages. If Translation Workbench has been enabled for your organization, these labels can then be translated into any of the languages supports.

This allows developers to create true multilingual apps by presenting information to users.

for example: help text or error messages – in their native language. You can create up to 5,000custom labels.

To access custom labels, from Setup, enter Custom Labels in the Quick Find box, then select Custom Labels.

Create Custom Labels

Create custom labels that can be referenced from Apex classes, Visualforce pages, or Lightning components to make an app multilingual.

custom labels in salesforce step by step guide

how to create custom labels in Salesforce

Note – You can’t change the language of an existing custom label.
Using Custom Label in Apex and VFP –
  • In Apex use the System.Label.Label_name syntax.
  • In Visualforce and Lightning components, use the $Label global variable.

Translate Custom Labels

Translations for custom labels determine what text to display for the label’s value when a user’s default language is the translation language.

create custom labels

how to create custom labels in Salesforce

  1. In the Translations related list, click New to enter a new translation or Edit next to the language to change a translation.
  2. Select the Language you are translating into.
  3. Enter the Translation Text. This text overrides the value specified in the label’s Value field when a user’s default language is the translation language.

Using Custom Label in Apex and Visualforce Page:

Syntax for custom label:

In Apex use System.Label.Labelname

In Visualforce page use {!$Label.Label_name}


public class CustomLabelController {
public String labelValue{get;set;}
public CustomLabelController() {
labelValue = System.Label.Description;

Visualforce Page:

<apex:page controller="CustomLabelController">
<h1>Custom labels In VF Page :</h1>
<apex:outputLabel value="{!$Label.Description}"/>
<h2>Custom Label From Controller -:</h2>

Below are the Pros and Cons of using Custom Label in Salesforce


  • Code base is prepared for multi-lingual support.
  • Common error messages or help text can be reused
  • Ability to use a label in Apex Code and Visualforce Pages
  • Allows the text to be maintained by a system administrator rather than a developer
  • Data integrity is enforced if a delete attempt is made on the label and it is referenced by a Visualforce page or Apex Code
  • Readability of code and pages is improved by the use of custom label properties


  • instance must have the Translation Workbench enabled
  • Increased time to develop and coordinate with the development team to ensure that custom labels are not used inappropriately
  • Limit of 1,000 characters and up to 5,000 custom labels. If developing for a large org you must take care to ensure the labels are manageable and utilized

Stay tuned to for more updates.

Thank you so much for reading my post. Feel free to ask doubts/Queries in the comment section below, and I’ll come again with an interesting topic about Salesforce So Please Share, Subscribe to our blog for the latest update.

Leave a Reply