I need to get dynamic query result which returns rows more then 50K. Database.query() has 50K limit so I am trying to use Database.executeBatch(). On click of apex button, I want to display rows in apex:repeat. executeBatch returns rows in execute method which does not update apex:repeat control.

Following is the code:

//called by apex button to display result in apex:repeat control
public PageReference searchUsers(){
id batchInstance=Database.executeBatch(this,200);
return null;

global Database.QueryLocator start(Database.BatchableContext BC)

        return Database.getQueryLocator(Query  + ' LIMIT 200');

    global void execute(Database.BatchableContext BC,List<SObject> scope)
        //Want to update apex:repeat control with the result

global void finish(Database.BatchableContext bc)

  • Database executeBatch starts a batch job running asynchronously, you won't be able to use that in your controller to display rows. Have you looked at the @readonly annotation which lets you exceed the 50,000 row limit? – Doug B Apr 29 '14 at 15:27

Normally, queries for a single Visualforce page request may not retrieve more than 50,000 rows. In read-only mode, this limit is relaxed to allow querying up to 1 million rows.

Set it on the page like this

<apex:page controller="SummaryStatsController" readOnly="true">

In addition to querying many more rows, the readOnly attribute also increases the maximum number of items in a collection that can be iterated over using components such as <apex:dataTable>, <apex:dataList>, and <apex:repeat>. This limit increased from 1,000 items to 10,000. Here is a simple controller and page demonstrating this:


  • @"Doug B", I have already added readOnly attribute to page, but I was not sure how to confirm wether it really consider 1 million rows. Will following line will return 1 million with readOnly attribute on page? List<user> userList = Database.query(query); – Sanjivani Apr 29 '14 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.