Search code examples
salesforcesoql

SOQL Count with multiple Where clauses


I am trying to count all the results that match multiple Where conditions in Salesforce. All these Where conditions exist under the same object that I am selecting from. It seems like it should be a simply query but my SQL and SOQL experience is limited.

Here's my code right now:

SELECT count() FROM Account
WHERE Success__c='yes'
AND Active__c='true'
AND Days__c>'30'
AND Days__c<'37'

Solution

  • It'd be useful to see the actual error message, but at a guess, you have quotes around things that shouldn't have them, e.g. you want

    SELECT count() FROM Account
    WHERE Success__c = 'yes'
    AND Active__c = true
    AND Days__c > 30
    AND Days__c < 37
    

    Also there are tools like SoqlX, the Force.com IDE and Workbench that'll let you run queries, so if Geckoboard is hiding the actual error message, you can work through getting a good query in one of these tools first.