Saturday, February 18, 2017

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.

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

No comments:

Post a Comment