Order By Schema

AVAILABLE API VERSION
API v59.0 and later

All sObjects in the schema have a corresponding RecordOrderBy type. The RecordOrderBy type combines the object API name with the _OrderBy suffix. For example:

The RecordOrderBy type is introduced by the RecordQueryAggregate type.

RecordOrderBy creates one input type per sObject type. For example, Account has a corresponding Account_OrderBy type that you can use with the orderBy argument.

The Account_OrderBy type contains fields of OrderByClause type. Some fields are shown here for brevity. We recommend that you use the Altair GraphQL client for a complete view of the schema.

The main types include:

  • AggregateOrderByStringClause - Defines aggregate functions used by fields of these types:
    • String
    • Id
    • DateTime
    • Time
    • Date
    • Email
    • PhoneNumber
    • Url
    • Picklist
  • AggregateOrderByNumberClause - Defines aggregate functions used by fields of these types:
    • Int
    • Double
    • Long
    • Latitude
    • Longitude
    • Percent
  • NoFunctionAggregateOrderByClause - Defines how null values are returned and how sorting order are used by fields of these types:
    • Boolean
    • Reference fields like AccountId and OwnerId

The AggregateOrderByStringClause type has several enumeration types.

Pass these types to the orderBy argument in the aggregate field.

  • function - The aggregate function to apply to the filter.
  • nulls - Orders null records either first or last.
  • order - Order the aggregate results by ascending or descending order.

The AggregateOrderByStringFunction enum values define aggregate functions for string fields like date, email, or Url and so on.

Use these values with string fields.

  • COUNT - Returns the number of rows matching the query criteria.
  • COUNT_DISTINCT - Returns the number of distinct non-null field values matching the query criteria.
  • MAX - Returns the maximum value of a field.
  • MIN - Returns the minimum value of a field.

The AggregateOrderByNumberClause type has several enumeration types.

Pass these types to the orderBy argument in the aggregate field.

  • function - The aggregate function to apply to the filter.
  • nulls - Orders null records either first or last.
  • order - Order the aggregate results by ascending or descending order.

The NoFunctionAggregateOrderByClause type has several enumeration types.

Pass these types to the orderBy argument in the aggregate field.

  • nulls - Orders null records either first or last.
  • order - Order the aggregate results by ascending or descending order.

The AggregateOrderByNumberFunction enum values define aggregate functions for number fields like double, long, percent and so on.

Use these values with numeric fields.

  • AVG - Returns the average value of a field.
  • COUNT - Returns the number of rows matching the query criteria.
  • COUNT_DISTINCT - Returns the number of distinct non-null field values matching the query criteria.
  • MAX - Returns the maximum value of a field.
  • MIN - Returns the minimum value of a field.
  • SUM - Returns the total sum of a numeric field.

The NullsOrder enumeration type specifies the order in which nulls appear in the result set. By default, null values are sorted first.

Use these values in the orderBy argument.

  • FIRST - Order the null values first. This is the default.
  • LAST - Order the null values last.

The ResultsOrder enumeration type specifies whether the results are ordered in ascending or descending order. By default, the result is ordered in ascending order.

Use these values in the orderBy argument.

  • ASC - Ascending order (default)
  • DESC - Descending order

Some fields like CreatedBy and Owner correspond to a _OrderBy type, which contains additional fields.

Aggregate Examples

SOQL and SOSL Reference: Date Functions