In Salesforce, Custom Labels are a feature that allows you to create and manage custom text values that can be easily used in your application's Apex code, Visualforce pages, and Lightning components. Custom Labels are similar to custom settings and custom metadata types in that they allow you to define custom configuration values for your application, but they are specifically designed to store text values that are displayed on your application's user interface.
Custom Labels are especially useful for multilingual applications, as they can be translated into multiple languages and then dynamically displayed based on the user's language preference. This makes it easy to create a single application that can be used by users all over the world.
To create a Custom Label in Salesforce, you must first navigate to the Custom Labels page in the Setup menu. From there, you can create a new Custom Label by clicking the New button and entering a label name and value. You can also specify the language for the label, add translations, and manage the visibility of the label.
Once you have created a Custom Label, you can use it in your Apex code, Visualforce pages, or Lightning components by referencing the label's name in a $Label global variable. For example, if you have a Custom Label named "MyLabel", you can display its value in a Visualforce page by using the following code:
Custom labels have a limit of 1,000 characters and can be accessed from an Apex class. To define custom labels, from Setup, in the Quick Find box, enter Custom Labels, and then select Custom Labels.
Retrieving Custom Label in Apex:
String cName = System.Label.companyName;
System.debug(cName );
Once you have created a Custom Label, you can use it in your Apex code, Visualforce pages, or Lightning components by referencing the label's name in a $Label global variable. For example, if you have a Custom Label named "MyLabel", you can display its value in a Visualforce page by using the following code:
<apex:outputLabel value="{!$Label.MyLabel}"/>