I have a picklist field 3 values Like Red,Blue,White. There are 50 records in the object with different picklist values. Now I need a query - How many records with Picklist value - Red and AND how many records with Picklist value - Blue and same for the third value - White?

It should show like Picklist - Red-15 ,Picklist - Blue-10, Picklist - White-25. If it is not Possible then need a query to show all records picklist value wise?

1 Answer 1


This is a type of "aggregate result" query, and it looks like this:

SELECT SomePicklist__c value, COUNT(Id) recordCount
FROM SomeObject__c
GROUP BY SomePicklist__c

The output would look like this:

value, recordCount
Red, 15
Blue, 10
White, 25

You can summarize up to 2,000 values this way, which is more than enough for a single picklist.

You can read more about it in GROUP BY | SOQL and SOSL Reference.

  • Awesome! Thanks sfdcfix. Can you please Provide challenging SOQLs like this
    – Frank
    Jul 22, 2018 at 23:57
  • @Frank The documentation covers everything you need to know.
    – sfdcfox
    Jul 23, 2018 at 0:14

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.