Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My app uses different types of custom settings. Let's call them SettingA__c and SettingC_c.

I want a method that handles both types of settings polymorphically.

private void handle(SObject setting) {
   String name = (String) setting.get('Name');

   if(setting.getValues(name) != null) {

This is not possible as getValues() is undefined on SObject and I could not find a common base object for Custom Settings in the docs.

share|improve this question
up vote 4 down vote accepted

This question and answer Dynamic invocation (or emulation) of the hierarchy custom setting getInstance() method are related. The solution there is to use SOQL to access the custom setting (impacting the SOQL governor limit) and then you can use the normal dynamic SOQL methods on the result.

It sounds like you are using list custom settings not hierarchical ones so your query can be simpler and pretty much like querying a normal SObject.

share|improve this answer
Do keep in mind that soql on custom settings does not leverage cache, which could be part of why you're using custom settings. – Samuel De Rycke Mar 19 '14 at 8:44
You also lose the intelligent hierarchical defaulting for hierarchical settings by doing this, but there's no other way of doing it dynamically. – ca_peterson Mar 19 '14 at 16:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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