The Salesforce documentation is notably terse in describing Considerations When Using GROUP BY
. The guidance provided for determining which fields can be grouped is simply:
The Field object associated with DescribeSObjectResult has a groupable field that defines whether you can include the field in a GROUP BY clause.
Further, the document states that
You can't use child relationship expressions that use the __r syntax in a query that uses a GROUP BY clause.
Which field types in fact permit grouping? Does the final sentence prohibit the use of custom relationships in GROUP BY
? Multiple previous questions have not yielded a conclusive statement.
Failure to use a properly groupable field yields the error
field 'FIELD_NAME__c' can not be grouped in a query call