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"


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];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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