[SalesForce] Using Custom Labels in a 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);

Best Answer

You can access these 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