Order Results

Order objects are used to order the result set of records. All sObjects in the schema have a corresponding order type created. The order type combines the object API name with the _OrderBy suffix. For example, Account has a corresponding Account_OrderBy type created.

Fields that have a scalar or Field Value Type that support ordering have a corresponding Input Object Field of type OrderByClause. The field types that support ordering are as follows:

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

The OrderByClause type allows you to specify ascending or descending order, as well which order null values appear in. Let's take a look at an example account object that demonstrates how fields map to Account_OrderBy.

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.

Here's an example orderBy argument on contacts.

The orderBy example translates to a SOQL ORDER BY statement.

Custom metadata types (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.