How to use an apex custom label in class?
I have the below If statements using some hard coded strings and I want to make them use as custom labels. I have created custom labels with the same String names as given below. So how can I make these statements to use the Custom Labels I created ?
if(monitoringFrequency == 'daily'){ return dateValue.addDays(1); }else if(monitoringFrequency == 'weekly'){ return dateValue.addDays(7); }else if(monitoringFrequency == 'monthly'){ return dateValue.addMonths(1);
You can access these apex custom labels like this:
if(monitoringFrequency == System.Label.daily){ return dateValue.addDays(1); }else if(monitoringFrequency == System.Label.weekly){ return dateValue.addDays(7); }else if(monitoringFrequency == System.Label.monthly){ return dateValue.addMonths(1); }
Do make sure that the names of the custom labels are correct.
For more information, see: https://help.salesforce.com/HTViewHelpDoc?id=cl_about.htm&language=en_US