---
schema_version: "1"
id: 5ded6eba1c48a00f9113e918a5a9fe014eaf988f00963d720163e560c96461a2
title: Order By Schema
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/graphql-api/graphql/guides/order-schema.md
canonical_url: https://developer.salesforce.com/docs/platform/graphql/guide/order-schema.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: de82e82d65ce8a8c15502aa3e054c87c71ea232b6bd1b8f1ffe01f6c60b5d3c1
products:
  - GraphQL API
---
# 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.

```
input Account_OrderBy {
  Id: OrderByClause
  Name: OrderByClause
  AnnualRevenue: OrderByClause
  Location__c: OrderByGeolocationClause
  Owner: User_OrderBy
  Parent: Account_OrderBy
}
```

## OrderByClause Type

Let's take a look at an example account object that demonstrates how fields map to `Account_OrderBy`.

```
type Account {
  Id: ID
  Name: StringValue
  AnnualRevenue: CurrencyValue
  Location__c: Geolocation
}
```

The `OrderByClause` type contains `order` and `nulls` enumeration types.

```
input OrderByClause {
  order: ResultOrder
  nulls: NullOrder
}
```

## 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.

```
# Specifies whether the results are ordered in ascending or descending order
enum ResultOrder {
  ASC
  DESC
}
```

## NullOrder Enum

The `NullOrder` enumeration type specifies the order in which nulls appear in the result set. By default, null values are sorted first.

```
# Specifies the order in which nulls appear in the result set
enum NullOrder {
  FIRST
  LAST
}
```

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.

```
type Contact {
  AccountId: IDValue
  Account: Account # the 'Contact' sObject has a relationship 'Account' which points at the 'Account' object
}

input Contact_OrderBy {
  AccountId: OrderByClause
  Account: Account_OrderBy # 'Account_OrderBy" is used as the input type for the 'Account' input object field
}

input Account_OrderBy {
  # has the order by fields for Account
}
```

## OrderByGeolocationClause Type

Geolocation fields map to the `OrderByGeolocationClause` type. Its constituent fields `Location__Latitude__s` and `Location__Longitude__s` map to the `OrderByClause` type.

```
input Account_OrderBy {
  Name: OrderByClause
  Location__c: OrderByGeolocationClause
  Location__Latitude__s: OrderByClause
  Location__Longitude__s: OrderByClause
}
```

The `DistanceInput` type specifies the latitude and longitude fields on a geolocation field.

```
DistanceInput {
    latitude: Float
    longitude: Float
}
```

For more information, see [Location-Based Filters](https://developer.salesforce.com/docs/platform/graphql/guide/filter/filter-location.md).

## See Also

[`ORDER BY` statement](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_orderby.htm)
