Featured image of post How to Count Salesforce Records by Day with SOQL

How to Count Salesforce Records by Day with SOQL

A SOQL example that groups CreatedDate by the running user’s local day with DAY_ONLY and convertTimezone, returning the ten days with the highest record counts.

Open the Developer Console Query Editor and run the query below.

Account is a standard-object example; replace it with the API name of the object you need. COUNT(Id) counts records in each group. The query converts dates to the running user’s time zone and returns the ten busiest days, not necessarily the ten most recent. Add a WHERE CreatedDate condition to limit the period. Dates with no records do not appear.

1
2
3
4
5
SELECT DAY_ONLY(convertTimezone(CreatedDate)), COUNT(Id)
FROM Account
GROUP BY DAY_ONLY(convertTimezone(CreatedDate))
ORDER BY COUNT(Id) DESC
LIMIT 10

References

comments powered by Disqus