PaginationCursor Class

This class represents a pagination cursor that can traverse a SOQL query result set. It contains methods that fetch rows by page. It also contains a method that returns the total number of rows in the result set.

Namespace

Database

Usage

A pagination cursor is created when a SOQL query is executed on a Database.getPaginationCursor() or a Database.getPaginationCursorWithBinds() call. When the SOQL query is invoked, the corresponding rows are returned from the pagination cursor.

Use a pagination cursor for traversing human-viewable data, such as a list of records in a UI. The maximum number of rows per pagination cursor is 100,000, regardless of whether the operation is synchronous or asynchronous.

For a comparison between pagination cursors and standard cursors, see Apex Cursors in the Apex Developer Guide.

For Apex pagination cursor limits, see Execution Governors and Limits in the Apex Developer Guide.

PaginationCursor Methods

The following are methods for PaginationCursor.

fetchDeleted(start, pageSize)

Fetches the number of deleted rows within the specified range. The method counts only rows deleted after the creation of the pagination cursor. Calling the PaginationCursor.fetchDeleted() method counts against the SOQL query limit, and the rows fetched count against the SOQL query row limit.

Signature

public Integer fetchDeleted(Integer start, Integer pageSize)

Parameters

start
Type: Integer
The zero-based index from which to begin checking for deleted rows.
pageSize
Type: Integer
The number of rows to check, beginning at the start index.

Return Value

Type: Integer

fetchPage(start, pageSize)

Fetches a page of rows from the result set. By default, the method skips rows deleted after the creation of the pagination cursor. The method also returns information used to fetch the next page. Calling the PaginationCursor.fetchPage() method counts against the SOQL query limit, and the rows fetched count against the SOQL query row limit.

Signature

public Database.CursorFetchResult fetchPage(Integer start, Integer pageSize)

Parameters

start
Type: Integer
The zero-based index from which to begin fetching rows.
pageSize
Type: Integer
The maximum number of rows to include on the current page.

Return Value

Type: Database.CursorFetchResult

Contains the rows for the current page and the information used to fetch the next page.

getNumRecords()

Gets the total number of rows in the SOQL query result set.

Signature

public Integer getNumRecords()

Return Value

Type: Integer