function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

How to use StandardSetController on more than 10.000 records?

I am very confused by running into an "Too many query locator rows: 10001" error when calling those lines in APEX:


global static List<DataRow__c> doGet() {
  	RestRequest req = RestContext.request;
	Integer pageNumber = Integer.valueOf(req.params.get('pn'));
	Integer pageSize = Integer.valueOf(req.params.get('ps'));
	Database.QueryLocator queryLocator = Database.getQueryLocator(QUERY);
	ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(queryLocator);
        return ssc.getRecords();

What I am trying to do is select records from a dataset larger than 30.000 records. I do thos in chunks of a few hundred records. To define a chunk I planned on using the upcoming new SOQL OFFSET feature.


Then I read that OFFSET cannot be used for my purpose aS OFFSET cannot have a value > 2000 (Why the heck is that?)


So I refactored my code to use StandardSetController and chunking via pageSize and pageNumber.


But now I am running into this "Too many query locator rows: 10001" error although I am doing no insert update or anything.

I am JUST creating this Query Locator.


What am I doing wrong?