[SalesForce] Using custom setting value in SOQL query

I'm having difficulty in creating a SOQL query using a custom setting value.

select count (0) from custom_object__c where date_field__c > custom_setting__c.date__c

Returning error

"Bind variables only allowed in Apex Code"

Best Answer

You can't access a custom setting directly within SOQL. You would need to bind the date to a variable. Something like below should work

Custom_Setting__c cs = Custom_Setting__c.getInstance();
Date myDate = cs.Date_Field__c;

List<AggregateResult> result  = [select count(Id) total from Custom_Object__c Where Date_Field__c >: myDate];