Using List Custom Settings in Salesforce.com

Custom Settings were introduced by salesforce in winter 10 release and could be used to store data which is more frequently accessed. Custom settings can be called using their own API. They can be fetched in formula fields, Validation rules ,Apex and Web Services.

If Custom Settings are only used to store data then why not create a object and store data ?

Custom settings are similar to creating a object. Infact custom settings creates a object in background which is not visible to us. You create fields in custom settings as you create in a custom object. The only difference is that custom settings are exposed to the Application Cache(so they are quicker) and they do not count against the SOQL limits.

Lets take an example which will give a clear picture how to use custom settings.

This examples is taken from Jeff Douglas's blog. Salesforce doesn't have country codes. So to achieve the functionality create a custom setting as shown in the snapshot below-



Create few entries by clicking on the manage button. Snapshot is given for your reference.



After adding the records you can access the records using simple soql query
example- Select Id, Name , ISO_Code__c from ISO_Country__c

Custom Settings have their own methods to access. They are getInstance() and getValues(). To access the record using the values of Name column or any other Columns.


ISO_Country__c code = ISO_Country__c.getInstance(‘AFGHANISTAN’);



0 comments:

Post a Comment