Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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];
System.debug(sb.size());

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
add comment

1 Answer 1

up vote 2 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 ? –  RisingPhoenix May 24 at 14:36
1  
No .Never query.Why would you query use if and get the data required .Querying will cause governor limit –  Mohith Shrivastava May 24 at 14:38
1  
@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 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 at 15:18
add comment

Your Answer

 
discard

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.