using custom label in apex code

Custom labels are used to store custom text values which can be accessed in apex code or visualforce pages. It is also possible to translate these custom values in different languages. A custom label can hold up to 1000 characters in it and an org can have a total of 5000 custom labels.
You can Create a custom label by navigating to set up -> create -> custom label

In the below example let us see how we can access the custom label in apex. Let's assume we have created a custom label of name category with a value "A Custom Label Value"

Visualforce page
<apex:page controller="custlabelcontroller">
   <apex:form >
     <apex:pageblock >
       Value stored in custom label is: {!customValue}

Public class custlabelcontroller{
Public string customValue{get;set;}
  Public custlabelcontroller(){
  customValue = Label.category;


  1. why we using custom label and what is use of it please do reply....

  2. Custom Settings or labels both work. One benefit of labels is that they are included in the metadata when you refresh sandboxes or create a package

  3. Compile Error: Invalid external string name: category at line 4 column 18

  4. Create a custom label by navigating to set up -> create -> custom label.

    give the custom label's name as category and with some value. The value given in the value attribute will be available in the output.