Another Salesforce blog!!!

Salesforce, Apex

Dynamically access Custom Labels from Apex Class

Retrieve Salesforce custom label dynamically in Apex
Ever wonder if it is possible to retrieve custom labels dynamically but not sure whether it is possible? Well, the answer is yes. You can retrieve custom labels dynamically.

Here is how you can achieve it. You just need to integrate the following code in your apex class.

 public static String getLabelString(String labelName ){
    Component.Apex.OutputText output = new Component.Apex.OutputText();
    output.expressions.value = '{!$Label.' + labelName + '}';
    return String.valueOf(output.value);

Leave a Reply

Your email address will not be published.