Skip to content

Salesforce Custom Labels: A Tutorial for Beginners

Custom Labels

Salesforce Custom Labels are an essential tool for developers and admins who aim to maintain a multi-language environment or simply want a way to manage some hard-coded values without changing the code. This tutorial will guide you through the creation, access, and implementation of custom labels in Salesforce.

What are Salesforce Custom Labels?

Salesforce Custom Labels are custom text values that you can access from Apex classes, Visualforce pages, Lightning components, and even Flow. The primary use is for storing values that can be translated into any language Salesforce supports, making them ideal for developers working in a multilingual organization.

Why use Custom Labels?

  1. Multilingual Support: They offer an easy way to support multiple languages without hardcoding strings in your logic.
  2. Reusability: Avoid hardcoding specific strings across multiple components or classes. Use a label instead and refer to it everywhere.
  3. Manageability: Update a label in one place, and it gets reflected everywhere it’s used.

Creating a Custom Label

  1. Log in to Salesforce and click on the App Launcher (grid icon).
  2. Type “Custom Labels” in the search box and select Custom Labels from the dropdown.
  3. Click on the New Custom Label button.
  4. Fill in the following details:
    • Label: A short description (this is what you’ll refer to in your code).
    • Name: A unique API name for the label.
    • Value: The text value you want to store.
    • Description (optional): Additional details about the label.
    • Categories (optional): Grouping mechanism for organization.
    • Protected: Choose whether the label should be available only within its own managed package.
    • Language: Default is the organization’s default language.
  5. Click Save.

Accessing Custom Labels

Once you’ve created your labels, you can use them in various Salesforce platforms:


String myLabel = System.Label.Your_Custom_Label_Name;



<apex:outputText value="{!$Label.Your_Custom_Label_Name}" />


Lightning Component:



Flow: Use the global variable $Label and the custom label’s unique name.



Example: Using Custom Labels

Imagine you have a Visualforce page and you want to display a greeting message that can be translated. Instead of hardcoding the message:

<apex:outputText value="Hello, user!" />


You can use a custom label:

  1. Create a custom label named Greeting_Message with the value “Hello, user!”.
  2. Update your Visualforce page:
    <apex:outputText value="{!$Label.Greeting_Message}" />


Now, whenever you want to change the greeting message, you don’t need to edit the Visualforce page, just update the custom label’s value.

Translation Workbench

For organizations with multilingual users, translating the labels is straightforward. Use Salesforce’s Translation Workbench:

  1. Enable the Translation Workbench from Setup.
  2. Add languages you want to support.
  3. Translate your custom labels for each supported language.

Users with their language preference set will automatically see the translated version of the label.

Salesforce Custom Labels are a versatile tool in the Salesforce developer’s and admin’s toolkit. They provide a way to manage text values centrally, support multilingual environments, and improve the maintainability of the platform. As a best practice, always consider using custom labels when you have strings that might change or need translation.


Salesforce Data Loader: An essential data manipulation tool

Data Classification in Salesforce


Join the conversation

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

error: Content is protected !!