2

Can I access the value of a custom label during an Apex test? Do I have to use "SeeAllData=true" to get the value? If so, what value do I get back when not using "SeeAllData=true"?

The documentation is silent on these points.

https://help.salesforce.com/apex/HTViewHelpDoc?id=cl_about.htm&language=en_US

  • 1
    Custom labels should be accessable during test methods just like custom fields, etc are. I would think a great way to confirm this would be to try it out. – Eric Aug 18 '15 at 20:28
  • I will certainly be doing so. I have hopes that someone already knows the answer. – Jagular Aug 18 '15 at 20:47
5

Just tested, Test class can access custom label. No need to enable seeAllDate=true.

3

Custom labels should be accessable during test methods just like custom fields, etc are. I would think a great way to confirm this would be to try it out

This will take 1 minute to test:

@isTest
private class testLabel{

     private static testmethod void basicTest(){
        String testLbl = Label.<custom label name>;
        system.debug(logginglevel.error,testLbl);

     }

}

I would but I am not able to get in an org at the moment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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