Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In apex you can reference a custom label with system.Label.labelName, but is there a more dynamic way to get a custom label for example system.Label.get(labelName)? I can't find anything like this in the documentation but was hoping it was possible.

I'm trying to have custom labels for fields to support multiple languages. The list of fields I'm showing is built in the controller and displayed inside an apex:repeat tag so I can't hardcode the labels. Is there a way to accomplish this?


share|improve this question
If you're just looking for translating the field labels (as opposed to any other text on your visualforce pages), you'll want to use the translation workbench as fields are by nature multi-lingual already. – Ralph Callaway Feb 18 '13 at 23:48
Standard fields are but what about custom fields? – Phil B Feb 19 '13 at 3:14
Yep, all fields, including custom ones, can be translated using the translation workbench. – Ralph Callaway Feb 19 '13 at 15:12
up vote 21 down vote accepted

No, you can't reference labels dynamically in apex. You can vote for this idea here. However, you can reference them dynamically from visualforce so you can put them on the page like so:

public class MyController
    public String mylabel{get; set;}

    public MyController()

<apex:page Controller="MyController">
    <apex:outputText> {!$Label[mylabel]} </apex:outputText>
share|improve this answer
Wow I didn't know about the dynamic access in VF. Very cool. Must try soon! Thanks :) – techtrekker Feb 18 '13 at 19:12
Thanks, it sounds like this is the best option currently available. I did find a more popular version of the idea that is asking a little bit more as well (retrieving translations): – Phil B Feb 18 '13 at 19:31
Very cool! Did not know that was possible. – Ralph Callaway Feb 18 '13 at 23:47

Following is a code snippet of a work-around. But it has a limitation of working Only in a constructor of a VF page controller class.

string labelName = 'DemoLabel';
Component.Apex.OutputText output;
output = new Component.Apex.OutputText();
output.expressions.value = '{!$Label.' + labelName + '}';
string labelValue = string.valueOf(output.value);

Hope this helps...

share|improve this answer
This is a nice solution. Thanks! – PepeFloyd May 7 '15 at 12:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.