Order By Schema

AVAILABLE API VERSION
API v56.0 and later

Each orderable field on a record, such as on an account, gets a corresponding field on Account_OrderBy with type OrderByClause. The OrderByClause type allows you to specify ascending or descending order, as well as the order of null values.

Orderable fields are linked to InputObject types like OrderByClause, depending on their type, such as User_OrderBy for user fields, or OrderByGeolocation for geolocation fields.

Account_OrderBy
1input Account_OrderBy {
2  Id: OrderByClause
3  Name: OrderByClause
4  AnnualRevenue: OrderByClause
5  Location__c: OrderByGeolocationClause
6  Owner: User_OrderBy
7  Parent: Account_OrderBy
8}

OrderByClause Type 

Let’s take a look at an example account object that demonstrates how fields map to Account_OrderBy.

Account type
1type Account {
2  Id: ID
3  Name: StringValue
4  AnnualRevenue: CurrencyValue
5  Location__c: Geolocation
6}

The OrderByClause type contains order and nulls enumeration types.

OrderByClause type
1input OrderByClause {
2  order: ResultOrder
3  nulls: NullOrder
4}

ResultOrder Enum 

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

ResultOrder enumeration type
1# Specifies whether the results are ordered in ascending or descending order
2enum ResultOrder {
3  ASC
4  DESC
5}

NullOrder Enum 

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

NullOrder enumeration type
1# Specifies the order in which nulls appear in the result set
2enum NullOrder {
3  FIRST
4  LAST
5}

The order by object has input object fields for each parent relationship the object has. The field has the same name as the parent relationship, and have the OrderBy type corresponding to the object that the relationship points at.

1type Contact {
2  AccountId: IDValue
3  Account: Account # the 'Contact' sObject has a relationship 'Account' which points at the 'Account' object
4}
5
6input Contact_OrderBy {
7  AccountId: OrderByClause
8  Account: Account_OrderBy # 'Account_OrderBy" is used as the input type for the 'Account' input object field
9}
10
11input Account_OrderBy {
12  # has the order by fields for Account
13}

OrderByGeolocationClause Type 

Geolocation fields map to the OrderByGeolocationClause type. Its constituent fields Location__Latitude__s and Location__Longitude__s map to the OrderByClause type.

Account_OrderBy
1input Account_OrderBy {
2  Name: OrderByClause
3  Location__c: OrderByGeolocationClause
4  Location__Latitude__s: OrderByClause
5  Location__Longitude__s: OrderByClause
6}

The DistanceInput type specifies the latitude and longitude fields on a geolocation field.

DistanceInput type
1DistanceInput {
2    latitude: Float
3    longitude: Float
4}

For more information, see Location-Based Filters.

See Also 

ORDER BY statement