We can access a custom label in Salesforce these ways:
Visualforce: {! $Label.Label_API_Name }
Lightning component: {!$Label.c.Label_API_Name} (Note: there are dynamic methods, too.)
Apex: String someLabel = System.Label.Label_API_Name;
OR
Check this method, it will return the string of the custom label by the string Name sent.
// This method return the String value for the Label id public String getLabelString(String labelName ){ Component.Apex.OutputText output = new Component.Apex.OutputText(); output.expressions.value = ‘{!$Label.’ + labelName + ‘}’;
return String.valueOf(output.value); }
Comments