Order Aggregate Results

AVAILABLE API VERSION
API v59.0 and later

Use the orderBy argument to sort the aggregate results alphabetically in either ascending or descending order. You can also specify if null values appear first in the result set.

When querying a RecordAggregate, you can pass in an aggregate function and a orderBy argument. If you don't need aggregation, use the RecordQuery type instead.

The orderBy argument behaves like the SOQL ORDER BY clause.

To use the orderBy argument, your field must be grouped or aggregated.

All sObjects in the schema have a corresponding order type. The order type combines the API name with the _OrderBy. For example, under the RecordQueryAggregate fields, Account has a corresponding Account_OrderBy type. See Aggregate Schema.

The following field types support ordering. Each field type corresponds to an AggregateOrderByClause type. See Order By Schema.

  • Int
  • String
  • Boolean
  • Id
  • DateTime
  • Time
  • Date
  • TextArea
  • LongTextArea
  • PhoneNumber
  • Email
  • Url
  • Currency
  • Geolocation
  • Longitude
  • Latitude
  • Picklist
  • Long
  • Double
  • Percent
  • Base64