You need to sign in to do that
Don't have an account?
Jan4C
How can I access Custom Labels from Apex code classes?
Hi,
in the Winter'09 release notes it says "Custom labels are custom text values, up to 1,000 characters in length, that can be accessed from Apex classes or Visualforce pages".
I could easily find how to access these labels from a visualforce page, but nowhere I can find how to access them from an apex class.
I need this because I have a class that dynamically generates labels for a certain table in a vf page. But I want to use Custom Labels (and the translation workbench) to get these translated in various languages.
Is there an object, something like Label with a static function like 'getLabel(String)'? Or is this not released in Winter '09?
All Answers
Cannot find any documentation either....
Please suggest
https://help.salesforce.com/HTViewHelpDoc?id=cl_about.htm&language=en_US
I found a way to get the Custom Label String dynamically.
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);
}
Visualforce Page: $Label.Label_API_Name
Lightning Component Page {!$Label.c.Label_API_Name}
Apex Class String getLabelName = Label.Label_API_Name;
or directly System.Label.Label_API_Name
hope this helps you.
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;
Here's the relevant documentation for each:
https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_DETAIL&dc=General_Development&criteria=OPENQUESTIONS&id=9062I000000Xm11QAC
And where could I find a {!$Label.example} field in Salesforce to update it?
Thanks !