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

I am new to custom settings.

My assumption is Custom Settings are part of application cache as such querying against custom settings do not count against SOQL limit.

This is my code snippet (executed from developer console).

Combinations__c is a custom setting.

String q='Creative';
String t='Dealer';
String a='Expand';
String sa='Included';

List<Combinations__c> sb = [SELECT ID FROM Combinations__c WHERE Queue__c=:q AND Type__c=:t AND Area__c=:a AND Sub_Area__c=:sa];

This is my log as shown below.As you can see it is firing one SOQL query.

I am confused :(

enter image description here

I believed querying against Custom Settings do not count against limit.

Can someone explain why a SOQL is fired and is counted against the limit of 100 even when I am querying against custom settings ?

share|improve this question
up vote 5 down vote accepted

Querying custom settings will surely count against limits .

The way this custom settings can be used is via apex methods for custom settings ,not by using SOQL on them .Using SOQL on them defeats the purpose of using these

To access data from custom settings use the following if its list

List<Combinations__c> mcs = Combinations__c.getall().values();//Prefer this and this avoids SOQL on them 

And then you can filter as per your need using IF statements .

Or to retrieve from your Name you can use get Instance or get values methods

Combinations__c myCS1 = Combinations__c.getValues('your custom settting name here');
share|improve this answer
Thanks. List<Combinations__c> mcs = Combinations__c.getall().values();//Prefer this and this avoids SOQL on them Using this I can intialize a list of the combinations (each list element comprising of one combination I assume). After this list (mcs) is intialized can we query against this list for a particular combination of queue,type,area and subarea ? – ZenSeeker May 24 '14 at 14:36
No .Never query.Why would you query use if and get the data required .Querying will cause governor limit – Mohith Shrivastava May 24 '14 at 14:38
@MohithShrivastava Querying allows you to filter and order the data because SOQL is good at that and will consume 1 of the 100 allowed queries only. So "never" is too strong a term. – Keith C May 24 '14 at 15:15
@KeithC Yes agreed on that.It depends on context .Like if logic is lot and somebody wants to save query i would go with If ,else i would go with query itself . – Mohith Shrivastava May 24 '14 at 15:18

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.