---
schema_version: "1"
id: 8056da93788af12c4a367e79471bbae7826d8edf5a5f9703f81b5e8ccc53668f
title: Order By Examples
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/graphql-api/graphql/guides/order-examples.md
canonical_url: https://developer.salesforce.com/docs/platform/graphql/guide/order-examples.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: d0189d8fba8842ceac2e62ea7e7f4da3d99a818cce43be056ae01baeb6472264
products:
  - GraphQL API
---
# Order By Examples

| AVAILABLE API VERSION |
| --------------------- |
| API v56.0 and later   |

Order objects are used to order the result set of records. All sObjects in the schema have a corresponding order type. The order type combines the object API name with the `_OrderBy` suffix. For example, `Account` has a corresponding `Account_OrderBy` type.

## Example: Order By Account Names

Pass in the `orderBy` argument to the object.

```
query accounts {
  uiapi {
    query {
      Account ( orderBy: {
        Name: {
            order: ASC
          }
        }) {
        edges {
          node {
            Id
            Name {
              value
            }
          }
        }
      }
    }
  }
}
```

The query returns the following example response.

```
{
  "data": {
    "uiapi": {
      "query": {
        "Account": {
          "edges": [
            {
              "node": {
                "Name": {
                  "value": "Alpha Dynamics"
                }
              }
            },
            {
              "node": {
                "Name": {
                  "value": "Burlington Textiles"
                }
              }
            }, // more results here
          ]
        }
      }
    }
  },
  "errors": []
}
```

## Example: Order By Child Contacts on Accounts

Here's an example `orderBy` argument for contacts on account records.

```
query AccountWithChildrenAccounts {
  uiapi {
      query {
          Account(where: { Name: { eq: "Alpha Dynamics" } }) {
              edges {
                  node {
                      Id
                      Name {
                          value
                      }
                      Contacts ( orderBy: {
                        Name: {
                          order: ASC
                        }
                      }) {
                          edges {
                            node {
                              Name {
                                value
                              }
                            }
                          }
                      }
                  }
              }
          }
      }
  }
}
```

The query returns the following example response.

```
{
  "data": {
    "uiapi": {
      "query": {
        "Account": {
          "edges": [
            {
              "node": {
                "Id": "001RM000005ZdMGYA0",
                "Name": {
                  "value": "Alpha Dynamics"
                },
                "Contacts": {
                  "edges": [
                    {
                      "node": {
                        "Name": {
                          "value": "Amy Taylor"
                        }
                      }
                    },
                    {
                      "node": {
                        "Name": {
                          "value": "Caroline Kingsley"
                        }
                      }
                    },
                    {
                      "node": {
                        "Name": {
                          "value": "Jennifer Wu"
                        }
                      }
                    }
                  ]
                }
              }
            }
          ]
        }
      }
    }
  },
  "errors": []
}
```

**note:** [Custom metadata types](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_custommetadatatype__mdt.htm) (types ending in `__mdt`) don't support ordering through parent relationships, and so they don't have any input object fields corresponding to parent relationships on the `OrderBy` object.
