+ Start a Discussion

Custom Labels - used as configuration parameters?

Are there any reasons why Custom Labels can't be used as configuration paramters in apex classes/triggers?



For example,


String queryFields = System.Label.CustomQueryFieldsAccount;


List<Account> = Database.query("SELECT "+queryFields+"FROM Account);

Message Edited by dev_force on 03-27-2009 12:13 PM

No reason not to use Labels. In fact this is a good way to set up your application, and get hard coding out of your code.

I use Labels for this kind of thing all the time.


I would check to see if your queryFields variable is set up correctly before you proceed with your query. Just as an extra step to safe guard the user experience.

ie. You could check to see if queryFields has all the correct comma placements, and if not throw a custom error message before the user would get a nasty query exception.


Labels can let the business tweak the behavior of our code without code changes.