+ Start a Discussion

How can write a Soql query group by lastmodifieddate

Shailesh DeshpandeShailesh Deshpande
You cannot. LastModifiedDate is not a groupable field.

When you’re creating SOQL queries with the GROUP BY clause, there are some considerations to keep in mind.
  • Some object fields have a field type that does not support grouping. You can't include fields with these field types in a GROUP BY clause. The Field object associated with DescribeSObjectResult has a groupable field that defines whether you can include the field in a GROUP BY clause. For egLead.LastModifiedDate.getDescribe().isGroupable() returns false.
If you wish to group using LastModifiedDate, you will have to develop a custom logic, like have map with key as date and value as list of records modified on that date.