getNextPage() and getPreviousPage()

You can use the Database.getNextPage() and Database.getPreviousPage() functions to access next or previous pages respectively from the database cursor.

The getPreviousPage()function fetches records in the forward direction. That is, if the cursor is on the 11th record and you call this function, it returns records from 1 to 10, and not from 10 to 1.

The getNextPage() function returns an empty array when it reaches the end of the result set. Similarly, the getPreviousPage() function returns an empty array when it reaches the beginning of the result set.

Syntax

Object [] getNextPage(String cursorName, int pageSize)
Object [] getPreviousPage(String cursorName, int pageSize)

Parameters

Parameter Type Description
cursorName String The name of the database cursor.
pageSize Integer The number of concepts or records to be fetched from the database for each page.

If the pageSize is -1, then the default page size given for the cursor is used. The default is 500.

return Object[] Object[] The array of the returned resultset data.

If resultConceptURI is specified, the array is of resultConceptType. Else, it is in the form of n-tuple object array, where each tuple is an array of the values of the returned resultset data.

Example for getNextPage

Database.setCurrentConnection("/SharedResources/Oracle.sharedjdbc");
String jdbcURI="/SharedResources/HR_DB_Conn.sharedjdbc";
String cursorName="EmpCursor";
String resultTypeURI="/Concepts/HR/EMPLOYEES";
String sql="select * from employees";
int pageSize=10 ;
Object requestObj=null;
String cursorName=Database.createQuery(jdbcURI,cursorName,resultTypeURI,sql,pageSize,requestObj);
System.debugOut(" Opened Cursor: " + cursorName);
   Concept[] empCepts={};
   empCepts=Database.getNextPage(cursorName, 10);
   System.debugOut(" Database.getNextPage() fetched " + empCepts@length + " rows");

Example for getPreviousPage

Database.setCurrentConnection("/SharedResources/Oracle.sharedjdbc");
String jdbcURI="/SharedResources/HR_DB_Conn.sharedjdbc";
String cursorName="EmpCursor";
String resultTypeURI="/Concepts/HR/EMPLOYEES";
String sql="select * from employees";
int pageSize=10 ;
Object requestObj=null;
String cursorName=Database.createQuery(jdbcURI,cursorName,resultTypeURI,sql,pageSize,requestObj);
System.debugOut(" Opened Cursor: " + cursorName);
   Concept[] empCepts={};
   empCepts=Database. getPreviousPage (cursorName, 10);
   System.debugOut(" Database. getPreviousPage () fetched " + empCepts@length + " rows");