+ Start a Discussion

Do we have Query More functionality in APEX?

Can we have querymore in APEX. I have around 1200 records which needs to be displayed at one go and I as read there is a limitation for 1000 records in APEX queries. So is there anything of QueryMore sort in APEX, or if not is it possible to achieve this.
Ron WildRon Wild
You can use a SOQL query for loop if the results are too large (for example if the syntax below causes a runtime exception)

Account[] accts = [SELECT id FROM account];

The SOQL query for loop might look like this:

// Use this format if you are not executing DML statements
// within the for loop
for (Account a : [SELECT id, name FROM account
WHERE name LIKE 'Acme']) {
// Your code without DML statements here

Or this:

// Use this format for efficiency if you are executing DML statements
// within the for loop
for (List<Account> accts : [SELECT id, name FROM account
WHERE name LIKE 'Acme']) {
// Your code here
update accts;

Apex will invoke the queryMore feature behind the scenes in these scenarios.

Thanks Ron, Even i was looking for the same thing.

I tried the line of code you provided and it worked well till 10000 records. If the number of records are more than 10000, it shows an error. Just wanted to know your view on this. Is there a workwround on this also??

Thanks in advance!!

Ron WildRon Wild
That depends on the error.  If you hit governor limits there are work-arounds.  If you've uncovered a bug in the SOQL for loop construct, I'll have to defer to an expert from Salesforce.

- R
On execution is says:

01:59:43 ERROR - Evaluation error: System.Exception: Too many query rows: 10001
01:59:43 ERROR - Evaluation error: Class.Test.qry: line 6, column 30

setting the limit to 10000, makes the query work fine. I think this is the governer limit issue, if yes, can you please suggest the perfect way to resolve it or is it just putting some condition in the query which would narrow down the results.

Please advise.
Ron WildRon Wild
Search the discussion group for "Execution governor exception"  ... I've already posted a suggestion for this problem.

Hi Ron,

I am facing the same problem. There are over 40,000 contacts in the production instacne. I want to show those in my visual force page with some filter criteria. But there are atmost 10,000 query rows. If I put a limit 10,000 then it works fine. But if i try to get all the records a salesforce exception comes. Is there any method like queryMore so that i can get all the records.