How to use Custom Labels in Visualforce page and Apex Class

Custom labels are custom text values that can be accessed from Apex classes or Visualforce pages. The values can be translated into any language Salesforce supports. Custom labels enable developers to create multilingual applications by automatically presenting information (for example, help text or error messages) in a user’s native language.

You can create up to 5,000 custom labels for your organization, and they can be up to 1,000 characters in length.

1. Go to Setup –> App Setup –> Custom Labels.

2. Click ‘New Custom Label’ Button.

3. Fill in the details and Click ‘Save’ button.

Calling Custom Label in Visualforce page:

Use the global variable $Label to access the Custom Label value in Visualforce page.

Sample Code:

<apex:page standardController=”Account” extensions=”sample”>
<h1>Example for Custom labels</h1>
<apex:outputLabel value=”{!$Label.Sample}”/>
</apex:page>

Using Custom Label in Apex Class:

Custom labels are called in Apex using System.Label.Label_name.

Sample Code:

String samp = System.Label.Sample;

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome content in your inbox, every month.

We don’t spam! Please check your mail for confirmation.

Leave a Comment

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

Select Language »