function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
santosh duvvurisantosh duvvuri 

Custom settings

Hi All, Can any one tell me how to use custom settings to store error messages and use it in my apex class. Thanks & Regards Santosh Duvvuri
Best Answer chosen by Admin (Salesforce Developers) 
Ritesh AswaneyRitesh Aswaney

If you're familiar with Java Property Files (and in some ways Preferences), then Custom Settings may be considered an equivalent.

 

Two types - Hierarchical (can be referenced in Formula Fields and config too) and List.

 

Created from Setup > Develop > Custom Settings

 

API names of the Object and fields similar to a standard sObject. The great thing is that you don't need a SOQL Query to retrieve. For eg if Custom_Setting__c is ur custom setting (List Type), then you can retrieve a row with Name say 'FirstKey' by Custom_Setting__c.getInstance('FirstKey')

 

To apply it to your context, lets say you had an Error Code ERR001, which you saved in a Custom Setting Error_Messages__c, it can be rertrieved as Error_Messages__c.getInstance('ERR001')

This lets you have dynamic error messages, which are configurable

 

Here's a good post by the inimitable Jeff Douglas to get you started 

http://blog.jeffdouglas.com/2010/01/07/using-list-custom-settings-in-salesforce-com/