2021 Offer : Pay for 1 & Get 3 Months of Unlimited Class Access

- Salesforce Blogs -

How To Use Custom Labels In Apex Class In Salesforce?

Salesforce has grown to become the most successful customer relationship management solution, which has brought many businesses and their customers together under one roof. It is an integrated platform for CRM which lends power to all the departments in the business, including marketing, sales, commerce, and even the service a combined and single view of every customer. The success of the company can be measured by the fact that more than 150,000 businesses across the world, irrespective of their sizes have shown an unmatched level of growth. The company ever since its conception in 1999 has stayed committed to its time, value and even the equity to improvement in education, equality, and environment. It has helped change the lives of people by the creation of better jobs, lives and even communities.

Custom Labels in Salesforce

Custom labels refer to the custom text values, which are often sought from the apex classes, visual force pages, and even lightning components. For supporting the multilingual feature in an application, custom labels which offer a change or translation in the text values of a user into any other language which are supported by the salesforce are used. It is also helpful in providing the best in class user experience, which offers the application in the native language of the user. Thus, we can say that the custom labels are simple values in the text which are used by the users for translation in any of the salesforces supported languages. They give information in the native language of the user. In the case of Salesforce Visualforce page, it is used in three ways:

  • In Visualforce Page
  • In Apex Class
  • In JavaScript

salesforce Curriculum

 How to use Custom Labels for the content?

  • Firstly, you need to create custom labels for the content.

GotoIISetupIICreateIICustom Labels

How to use Custom Labels for the content?

Read: All About Salesforce Certifications You Must Know

How to use Custom Labels for the content?

  • Secondly, a page is created in visual force and apex class for showing the label as shown in the code.

Visualforce Page Code:

<apex:page controller="examplecustomlabel" language="de"> <apex:form><p> Render By Visualforce Page : {!$Label.German}</p> <p> Render By Apex Class : {!cstmLabel}</p> </apex:form> </apex:page>

Apex Class:

public class examplecustomLabel {
public string cstmLabel {Get; Set;}
public examplecustomLabel () {
//if you have namespace use
//Here German is Custom label name
cstmLable = system.Label.Germa;


Read: Salesforce VisualForce Interview Questions & Answers for Fresher, Experienced

Visualforce Page Code

Editing of Custom Labels

It has been seen that the custom labels can be created which can be referenced from various Apex classes, Visualforce pages, and even the Lightning components to make the app multilingual.

Editions and User Permissions

  • Creation, Editing and even Deletion of Custom labels are done by customization of the application
  • Creation, or overriding a translation is done by viewing Setup and Configuration and is designated as a translator.

Remember, that editing the attributes of the custom labels which are already installed as part of the managed package is not possible. You can only override the existing translations or even give the new translations for all the languages which are not a part of the package.

salesforce quiz

Editing can be done in the following steps:

  • You need to enter the Custom Label in the Quick Find box and then select the Custom Labels in the Setup.
  • Next, you have to click on the New Custom Label, for creation of the label. If you want to edit, you have to click Edit, which is next to the custom label.
  • Then you need to enter an easily recognizable term for identification of this custom label in the Short Description text box. The description used here is then used in merge fields.
  • Remember that the language of the existing custom label cannot be changed.
  • For the creation of a custom label: In the Name text box, you need to enter the name of label uses. This value is further used in the Apex and the Visualforce pages for referencing the custom label. The names have to contain only alphanumeric characters, have to begin with a letter, shall have no spaces or even the double-underscores and should be unique from all the rest of the labels in the org.
  • The Custom label can be marked as protected by checking the Protected document.
  • In the case of Categories, you have to enter the text for categorizing the label. This is particularly used in the filter criteria when custom label list views are created. Each category is separated by a comma. The total number of characters which are allowed in the text box of Categories is 255.
  • Nearly 1000 characters are used in the Value text box. This value can be translated in any language which is supported by the Salesforce.
  • The changes are finally saved.

Translations of Custom Labels

Translations of the custom labels determine what text will be displayed for a particular value of a label when the default language of the user is the translation language.

Read: Salesforce Developer Salary - How Much Does Salesforce Developer Make?

User Permissions Needed

  • Creation, Editing and even Deletion of Custom labels are done by customization of the application
  • Creation or overriding a translation can be done by managing translation or even viewing Setup and Configuration and is designated as a translator.

Translation can be done in the following steps:

  • Firstly, you have to enter Custom Labels in the Quick Find box and then pick up the Custom Labels in the Setup.
  • Next, you have to select the name of the custom label to open.
  • Moving further, you are required to Click on New in the Translations related list, for entering a new translation. You may instead Edit next to the language for changing a translation. In case if you hit on Delete, the Salesforce will confirm if you really want to delete, only then it will remove the translation from the custom label. You may then select the language in which you want to translate.
  • Finally, you have to enter the translation text, which ultimately overrides the values which are mentioned in the Value field of the label when the default language of the user is the translation language.
  • Lastly, you have to save the changes which are made.

Creating Custom Labels

Nearly 5000 custom labels can be created in the organization which can be up to 1000 characters long. The custom labels from the managed packages do not count towards this limit. Custom labels can be added to the application depending on the user interface.

  • In Apex, it uses the System.Label_name syntax.
  • In the case of Visualforce or Lightning components, it uses the $Label global variable.

free salesforce demo

For the creation of the custom labels, you have to enter the Custom Labels in the Quick Find box and then select the Custom Labels. The following syntax can then be used for accessing the labels in the Aura components:

  • $ Label.c.LabeLName for the default namespace
  • $ Label.namespace.LabelName in case there is org has a namespace or accessing a label in a managed package.


Custom Labels let developers create multilingual applications by the automatic presentation of information in the native language of the user. Custom labels are the text values which can be accessed from the Apex classes, Lightning Components, and even the Visualforce pages.

Read: Queueable Apex Job

    Janbask Training

    A dynamic, highly professional, and a global online training course provider committed to propelling the next generation of technology learners with a whole new way of training experience.


  • S


    This article contains very good information. It is very useful. Thanks for Sharing.


Trending Courses


  • AWS & Fundamentals of Linux
  • Amazon Simple Storage Service
  • Elastic Compute Cloud
  • Databases Overview & Amazon Route 53

Upcoming Class

-1 day 08 May 2021


  • Intro to DevOps
  • GIT and Maven
  • Jenkins & Ansible
  • Docker and Cloud Computing

Upcoming Class

-1 day 08 May 2021

Data Science

  • Data Science Introduction
  • Hadoop and Spark Overview
  • Python & Intro to R Programming
  • Machine Learning

Upcoming Class

5 days 14 May 2021


  • Architecture, HDFS & MapReduce
  • Unix Shell & Apache Pig Installation
  • HIVE Installation & User-Defined Functions
  • SQOOP & Hbase Installation

Upcoming Class

5 days 14 May 2021


  • Salesforce Configuration Introduction
  • Security & Automation Process
  • Sales & Service Cloud
  • Apex Programming, SOQL & SOSL

Upcoming Class

6 days 15 May 2021


  • Introduction and Software Testing
  • Software Test Life Cycle
  • Automation Testing and API Testing
  • Selenium framework development using Testing

Upcoming Class

4 days 13 May 2021

Business Analyst

  • BA & Stakeholders Overview
  • BPMN, Requirement Elicitation
  • BA Tools & Design Documents
  • Enterprise Analysis, Agile & Scrum

Upcoming Class

-1 day 08 May 2021

MS SQL Server

  • Introduction & Database Query
  • Programming, Indexes & System Functions
  • SSIS Package Development Procedures
  • SSRS Report Design

Upcoming Class

5 days 14 May 2021


  • Features of Python
  • Python Editors and IDEs
  • Data types and Variables
  • Python File Operation

Upcoming Class

5 days 14 May 2021

Artificial Intelligence

  • Components of AI
  • Categories of Machine Learning
  • Recurrent Neural Networks
  • Recurrent Neural Networks

Upcoming Class

13 days 22 May 2021

Machine Learning

  • Introduction to Machine Learning & Python
  • Machine Learning: Supervised Learning
  • Machine Learning: Unsupervised Learning

Upcoming Class

26 days 04 Jun 2021


  • Introduction to Tableau Desktop
  • Data Transformation Methods
  • Configuring tableau server
  • Integration with R & Hadoop

Upcoming Class

6 days 15 May 2021

Search Posts


Receive Latest Materials and Offers on Salesforce Course