Paginate with Record Connections

AVAILABLE API VERSION
API v56.0 and later

To retrieve more than 200 records, we recommend using an upper-bound limit. Using pagination without an upper-bound limit lets you retrieve up to 4,000 records only. In API v60.0 and later, you can switch from record connection pagination to upper-bound limit pagination, allowing you to retrieve more than 4,000 records.

Paging Through Results 

Record Connections paging uses the first and after arguments based on relay record connections, which follows the specification for forward pagination arguments.

  • The first argument is the maximum number of records to fetch as part of your query.

    The initial query results can return any number of records up to the number you specify in the first argument. For example, if you request five records and the initial query result returns four records, use the after argument to page to the remaining record.

    Note

  • The after argument is a cursor used to page through the result set. Use a returned cursor to continue paging through the result set from that cursor position. The after argument is typically set to the value of the endCursor field on the relay connection’s PageInfo. If you want to page from a particular element in the result set, use the cursor field from a relay edge.

Query accounts with pagination
1query accounts {
2  uiapi {
3    query {
4      Account {
5        edges {
6          node {
7            Id
8            Name {
9              value
10            }
11          }
12        }
13        totalCount
14        pageInfo {
15          endCursor
16          hasNextPage
17          hasPreviousPage
18        }
19      }
20    }
21  }
22}

The query results are as follows.

Query results with pagination information
1{
2  "data": {
3    "uiapi": {
4      "query": {
5        "Account": {
6          "edges": [
7            {
8              "node": {
9                "Id": "0011a000005slmbAAA",
10                "Name": {
11                  "value": "GenePoint"
12                }
13              }
14            },
15            {
16              "node": {
17                "Id": "0011a000005slmlAAA",
18                "Name": {
19                  "value": "United Oil & Gas Corp"
20                }
21              }
22            }, // 8 more account records (10 results by default)
23          ],
24          "totalCount": 26,
25          "pageInfo": {
26            "endCursor": "djE6OQ==",
27            "hasNextPage": true,
28            "hasPreviousPage": false
29          }
30        }
31      }
32    }
33  },
34  "errors": []
35}

This example returns the next set of results after the djE6OQ== end cursor from the previous example.

Query with first and after arguments
1query accounts {
2  uiapi {
3    query {
4      Account (first:5, after:"djE6OQ==") {
5        edges {
6          node {
7            Id
8            Name {
9              value
10            }
11          }
12        }
13      }
14    }
15  }
16}

The query results are as follows.

Query results after a given cursor
1{
2  "data": {
3    "uiapi": {
4      "query": {
5        "Account": {
6          "edges": [
7            {
8              "node": {
9                "Id": "0011a000005slmlAAA",
10                "Name": {
11                  "value": "United Oil & Gas Corp"
12                }
13              }
14            }, // more results
15            }
16          ]
17        }
18      }
19    }
20  },
21  "errors": []
22}

Here’s an example query for accounts with cursors using variables.

Query accounts with cursors
1query accountsWithCursors($first: Int, $after: String) {
2  uiapi {
3    query {
4      Account(first: $first, after: $after) {
5        edges {
6          node {
7            Id
8            Name {
9              value
10            }
11          }
12          cursor
13        }
14        pageInfo {
15          hasNextPage
16          hasPreviousPage
17          startCursor
18          endCursor
19        }
20      }
21    }
22  }
23}

The query returns the account IDs and names with cursor information.

Response for accounts with cursors query
1{
2  "data": {
3    "uiapi": {
4      "query": {
5        "Account": {
6          "edges": [
7            {
8              "node": {
9                "Id": "0015f00000Afmo9AAB",
10                "Name": {
11                  "value": "Burlington Textiles Corp of America"
12                }
13              },
14              "cursor": "djE6Mw=="
15            },
16            {
17              "node": {
18                "Id": "0015f00000AfmoAAAR",
19                "Name": {
20                  "value": "Pyramid Construction Inc."
21                }
22              },
23              "cursor": "djE6NA=="
24            },
25            {
26              "node": {
27                "Id": "0015f00000AfmoBAAR",
28                "Name": {
29                  "value": "Dickenson plc"
30                }
31              },
32              "cursor": "djE6NQ=="
33            },
34            {
35              "node": {
36                "Id": "0015f00000AfmoCAAR",
37                "Name": {
38                  "value": "Grand Hotels & Resorts Ltd"
39                }
40              },
41              "cursor": "djE6Ng=="
42            },
43            {
44              "node": {
45                "Id": "0015f00000AfmoDAAR",
46                "Name": {
47                  "value": "United Oil & Gas Corp."
48                }
49              },
50              "cursor": "djE6Nw=="
51            },
52            {
53              "node": {
54                "Id": "0015f00000AfmoEAAR",
55                "Name": {
56                  "value": "Express Logistics and Transport"
57                }
58              },
59              "cursor": "djE6OA=="
60            },
61            {
62              "node": {
63                "Id": "0015f00000AfmoFAAR",
64                "Name": {
65                  "value": "University of Arizona"
66                }
67              },
68              "cursor": "djE6OQ=="
69            }
70          ],
71          "pageInfo": {
72            "hasNextPage": true,
73            "hasPreviousPage": false,
74            "startCursor": "djE6MA==",
75            "endCursor": "djE6OQ=="
76          }
77        }
78      }
79    }
80  },
81  "errors": []
82}

Paging Through Record Connections Child Relationships 

You can page through the child records on a queried parent record. Paging on the parent and children records at the same time isn’t supported. The child relationships records in the response are paginated and include cursor and pagination information. Use the first argument to specify the number of records to return. The default is 10.

Query an account with children contacts
1query accounts {
2  uiapi {
3    query {
4      Account ( where: { Name: { eq: "Edge Communications" } } ) {
5        edges {
6          node {
7            Contacts ( first: 5 ) {
8                edges {
9                    cursor
10                    node {
11                        Name {
12                          value
13                        }
14                    }
15                }
16                totalCount
17                pageInfo {
18                  hasNextPage
19              }
20             }
21          }
22        }
23      }
24    }
25  }
26}

The query results are as follows.

Query results with 2 children contact records
1{
2  "data": {
3    "uiapi": {
4      "query": {
5        "Account": {
6          "edges": [
7            {
8              "node": {
9                "Contacts": {
10                  "edges": [
11                    {
12                      "cursor": "djE6MA==",
13                      "node": {
14                        "Name": {
15                          "value": "Sean Forbes"
16                        }
17                      }
18                    },
19                    {
20                      "cursor": "djE6MQ==",
21                      "node": {
22                        "Name": {
23                          "value": "Rose Gonzalez"
24                        }
25                      }
26                    }
27                  ],
28                  "totalCount": 2
29                }
30              }
31            },
32            {
33              "node": {
34                "Contacts": {
35                  "edges": [],
36                  "totalCount": 0
37                }
38              }
39            }
40          ]
41        }
42      }
43    }
44  },
45  "errors": []
46}

The maximum number of child relationship records to return can be specified using the first argument. However, if supplying a cursor value to the after argument of a child relationship, then the parent record must be limited to a single result. For example:

Query children records with cursors
1query paginateChild {
2  uiapi {
3    query {
4      Account(first:1) { # must limit to one result as we are paging through the child
5        edges {
6          node {
7            Cases(first:100, after:"djE6Mw==") {
8              edges {
9                cursor
10                node {
11                  Id
12                }
13              }
14            }
15          }
16        }
17      }
18    }
19  }
20}