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.
1 query accounts {
2 uiapi {
3 query {
4 Account ( orderBy : {
5 Name : {
6 order : ASC
7 }
8 } ) {
9 edges {
10 node {
11 Id
12 Name {
13 value
14 }
15 }
16 }
17 }
18 }
19 }
20 }
The query returns the following example response.
1 {
2 "data" : {
3 "uiapi" : {
4 "query" : {
5 "Account" : {
6 "edges" : [
7 {
8 "node" : {
9 "Name" : {
10 "value" : "Alpha Dynamics"
11 }
12 }
13 } ,
14 {
15 "node" : {
16 "Name" : {
17 "value" : "Burlington Textiles"
18 }
19 }
20 } , // more results here
21 ]
22 }
23 }
24 }
25 } ,
26 "errors" : [ ]
27 }
Example: Order By Child Contacts on Accounts
Here’s an example orderBy argument for contacts on account records.
1 query AccountWithChildrenAccounts {
2 uiapi {
3 query {
4 Account ( where : { Name : { eq : "Alpha Dynamics" } } ) {
5 edges {
6 node {
7 Id
8 Name {
9 value
10 }
11 Contacts ( orderBy : {
12 Name : {
13 order : ASC
14 }
15 } ) {
16 edges {
17 node {
18 Name {
19 value
20 }
21 }
22 }
23 }
24 }
25 }
26 }
27 }
28 }
29 }
The query returns the following example response.
1 {
2 "data" : {
3 "uiapi" : {
4 "query" : {
5 "Account" : {
6 "edges" : [
7 {
8 "node" : {
9 "Id" : "001RM000005ZdMGYA0" ,
10 "Name" : {
11 "value" : "Alpha Dynamics"
12 } ,
13 "Contacts" : {
14 "edges" : [
15 {
16 "node" : {
17 "Name" : {
18 "value" : "Amy Taylor"
19 }
20 }
21 } ,
22 {
23 "node" : {
24 "Name" : {
25 "value" : "Caroline Kingsley"
26 }
27 }
28 } ,
29 {
30 "node" : {
31 "Name" : {
32 "value" : "Jennifer Wu"
33 }
34 }
35 }
36 ]
37 }
38 }
39 }
40 ]
41 }
42 }
43 }
44 } ,
45 "errors" : [ ]
46 }
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.