[SalesForce] Dynamic Queries with Database.executeBatch()

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)
    {


    } 

Best Answer

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:

http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_readonly_context_pagelevel.htm

Related Topic