I have a field called Rating on Account which is having 3 picklist values: Hot, Warm, and Cold. I want to write a SOQL query to fetch the counts of each value. Like I want to know how many records have a Rating Hot value in the Rating field and so on for each value.
TechnicalSenior Salesforce DeveloperSalesforce DeveloperTo fetch the counts of each Rating value, I would use a GROUP BY clause in my SOQL query. The query would look like this:
SELECT Rating, COUNT(Id) FROM Account GROUP BY Rating
This will give me a count for each picklist value: Hot, Warm, and Cold. It’s efficient as it reduces the number of queries needed and provides a clear summary of the data in one call.