Field ‘Number__c’ can not be grouped in a query call

About this Error

The error “Field cannot be grouped in a query call” indicates that the field is not groupable in SOQL in Salesforce. This typically happens when the field is of a type that does not support the GROUP BY operation in the query.

Common Non-Groupable Field Types

  • Custom Number (double) field, fields with or without decimal and regardless of scale.
  • Address Compound Fields
    • Components of Address compound fields are groupable if their types otherwise allow it.
  • Geolocations, both custom and standard, and whether or not defined as having decimal places, including the compound field and components (location/double)
  • Long Text (string)
  • Rich Text (string)
  • Auto Number (string)
  • Multi-Select Picklist (string)
  • Percent (double), including custom Percent fields with or without decimal and regardless of scale.
  • Currency (double), including custom Currency fields with or without decimal and regardless of scale.
  • Roll-Up Summary Fields (double), including COUNT rollups.
  • Encrypted Text Fields (Classic Encryption; string)
  • Encrypted fields that use the probabilistic encryption scheme can’t be used with the SOQL and SOSL GROUP BY clauses
  • Date/Time (dateTime)
  • Time (time)
  • Formulas of types other than Checkbox and Date, including the otherwise-groupable String type.

Confirm Field Groupability using Apex

Use Schema Describe in Apex to check if the field supports grouping:

Schema.DescribeFieldResult fieldDesc = Schema.SObjectType.YourObject__c.fields.Number__c; System.debug('Is Groupable: ' + fieldDesc.isGroupable());
  • If isGroupable returns false, the field cannot be grouped.