+ Start a Discussion
Joseph DindingerJoseph Dindinger 

How can I check if a Custom Label exists?

Hi everyone,

I am helping build a product and would like users to be able to change an error message (without using the translate feature).  

Is there any way in APEX that I can check for the existence of a Custom Label?  Something like this:

<pre>
// THIS CODE WILL NOT SAVE IF THE "Label.Overwrite_Error" DOESN'T EXIST
String sError = Label.Standard_Error;
If(Label.Overwrite_Error != NULL) sError = Label.Overwrite_Error;
</pre>

Any help would be greatly appreciated!  I don't want to use Custom Settings if at all possible.

Thank you!
Best Answer chosen by Joseph Dindinger
SamuelDeRyckeSamuelDeRycke

No I don't think there's a straightforward way to do this. You could use the metadata/tooling api proably, but that's a lot of overhead and probably not a good design.

If you explicitly do not want translation, a custom setting should be an option ?