Group By Schema
| AVAILABLE API VERSION |
|---|
| API v58.0 and later |
All sObjects in the schema have a corresponding RecordGroupBy type. The RecordGroupBy type combines the object API name with the _GroupBy suffix. For example:
1type Account {
2 groupBy: Account_GroupBy
3 orderBy: Account_OrderBy
4}The RecordGroupBy type is introduced by the RecordQueryAggregate type.
RecordGroupBy Type
RecordGroupBy creates one input type per sObject type. For example, Account has a corresponding Account_GroupBy type that you can use with the groupBy argument.
The Account_GroupBy type contains fields of GroupByClause. Some fields are shown here for brevity. We recommend that you use the Altair GraphQL client for a complete view of the schema.
1input Account_GroupBy {
2 AccountNumber: GroupByClause
3 BillingCity: GroupByClause
4 BillingCountry: GroupByClause
5 CreatedBy: User_GroupBy
6 CreatedById: GroupByClause
7 Id: GroupByClause
8 Industry: GroupByClause
9 Name: GroupByClause
10 NumberOfEmployees: GroupByClause
11 OperatingHours: OperatingHours_GroupBy
12 Owner: User_GroupBy
13 OwnerId: GroupByClause
14 Ownership: GroupByClause
15 Parent: Account_GroupBy
16 ParentId: GroupByClause
17 # More fields here
18 type: GroupByType
19}GroupByType Type
The GroupByType type defines the type of Group By clause.
1type GroupByType {
2 GROUP_BY: GROUP_BY
3 ROLLUP: ROLLUP
4 CUBE: CUBE
5}GroupByType contains these fields.
GROUP_BY- The default grouping.ROLLUP- Adds subtotals for aggregated data in the query result.CUBE- Adds subtotals for all combinations of a grouped field in the query results.
GroupByClause Type
The GroupByClause type has a group field of type Boolean. Pass these fields to the groupBy argument in the aggregate field.
1type GroupByClause {
2 group: Boolean
3}The GroupByClause type contains the following field.
group- Pass intrueto thegroupByargument to group the query by the specific field. If true, the field is included in theGroup BySOQL clause.
User_GroupBy Type
Some fields like CreatedBy and OperatingHours correspond to a _GroupBy type, which contains additional fields of type OrderByClause or _GroupBy.
1type User_GroupBy {
2 AboutMe: OrderByClause
3 Account: Account_OrderBy
4 AccountId: OrderByClause
5 # Other User_GroupBy fields
6}GroupByFunction Enum
Use the GroupByFunction enumeration with fields of type DateTime and Time. Fields of type DateTime and Time cannot be included with their field name alone, and so providing group: true for those field types is invalid.
You can’t use group:true for fields of type DateTime and Time. Instead, use these fields with the aggregate functions. See Grouping Examples.
Note
1Enum GroupByFunction {
2 CALENDAR_MONTH
3 CALENDAR_QUARTER
4 CALENDAR_YEAR
5 DAY_IN_WEEK
6 DAY_IN_MONTH
7 DAY_IN_YEAR
8 DAY_ONLY
9 FISCAL_MONTH
10 FISCAL_QUARTER
11 FISCAL_YEAR
12 HOUR_IN_DAY
13 WEEK_IN_MONTH
14 WEEK_IN_YEAR
15}The GroupByFunction enumeration contains these values.
CALENDAR_MONTH- Returns a number 1 (January) to 12 (December) for the calendar month on a date field.CALENDAR_QUARTER- Returns a number 1 (January 1 - March 31) to 4 (October 1 through December 31) for the calendar quarter on a date field.CALENDAR_YEAR- Returns the calendar year on a date field.DAY_IN_WEEK- Returns a number 1 (Sunday) to 7 (Saturday) for the day of the week on a date field.DAY_IN_MONTH- Returns a number 1–31 for the day in the month on a date field.DAY_IN_YEAR- Returns a number 1–365 for the day in the year on a date field.DAY_ONLY- Returns a date for the day portion on a DateTime field, for example,2009-09-22for September 22, 2009.FISCAL_MONTH- Returns a number 1–12 for the discal month on a date field, which can differ fromCALENDAR_MONTHif your organization uses a fiscal year that does not match the Gregorian calendar. This field is not supported if your organization has custom fiscal years enabled.FISCAL_QUARTER- Returns a number 1–4 for the fiscal quarter on a date field, which can differ fromCALENDAR_QUARTERif your organization uses a fiscal year that does not match the Gregorian calendar. This field is not supported if your organization has custom fiscal years enabled.FISCAL_YEAR- Returns the fiscal year on a date field, which can differ fromCALENDAR_YEARif your organization uses a fiscal year that does not match the Gregorian calendar.HOUR_IN_DAY- Returns a number 1–24 for the hour in the day on a DateTime field. Only DateTime and Time fields are supported.WEEK_IN_MONTH- Returns a number 1–5 for the week in the month on a date field.WEEK_IN_YEAR- Returns a number 1–53 for the week in the year on a date field.
See Also
SOQL and SOSL Reference: Date Functions