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
JDevJDev 

Batch Apex Query Limits in Spring 10 ?

I have a batch apex query processing all contacts in a spring10 sandbox org (with about 170,000 total contact records) using a Query locator as below. If I use a Limit clause in the query the batch process excecutes OK - up to a point - I've run successfully with 1,000, 10,000 and 100,000 limits (no other change to batch or query code.) When I try 200,000 row limit, or leave the row limit off, I get failure on the first batch and no records processed.

 

As the contacts are in order by sequence, and the default batch scope is 200 rows, it looks as though something is preventing the batches from even being created (as the first 200 rows should be the same batch in all cases) - yet the doeumentation indicates we should be able to process 50 million records, so 200,000 doesn't seem like it should cause a problem.

 

Anyone have the same symptoms in a Spring 10 release / any suggestions on how to overcome the problem?

 

global Database.queryLocator
        start(Database.BatchableContext custContact){
                   return Database.getQueryLocator(
        [Select Id, RecordTypeId, LastName, Total_Case_Count__c, Name from Contact Where RecordTypeId = '0123000000007loAAA' AND Name!= 'Anonymous Customer' Order by LastName limit 100000]);
    }

Best Answer chosen by Admin (Salesforce Developers) 
JDevJDev

Confirmed problem was sandbox limits - I set row limit to 100 to pass tests and when not in test mode run with no limit clause.  In Sandbox without limit clause the batch process fails in first batch with no error message. When run in production with no limit clause the process runs to conclusion without error. Would be nice to get an error message in sandbox.

All Answers

ScoobieScoobie

Do you get any error messages? Also, can you upload your execute method. There may be governor limits exceeded in there.

JDevJDev

No error messages -just  fails on first batch when the query locator has no limit clause or 200000 limit, works fine with 100000 limit or less so it doesn't seem to be anything in execute or governor limits as the same 200 rows would be processed in the first batch for a 200000 row limit as a 10000 row limit and given the order by clause it would process the same database records in the batch.

 

It seems to me the query optimizer is just deciding the query plan is too great and failing the process, but that's not what the documentation says and makes it cumbersom to launch from a UI and impractical as a scheduled job.

imuino2imuino2

It depends on your org platform, but probably the problem is that your limit is 100,000 rows per query.

 

Ignacio.

JDevJDev

Thanks, it's unlimited - but also full sandbox - so there may be a batch apex limit - nothing in the docs but the limit idea makes sense. I'll see if I can promote it to production with no limits and see if it runs there.

 

Be nice to see better documentation of APEX batch, better batch error reporting, support for aggregate queries and a real scheduler!

JDevJDev

Confirmed problem was sandbox limits - I set row limit to 100 to pass tests and when not in test mode run with no limit clause.  In Sandbox without limit clause the batch process fails in first batch with no error message. When run in production with no limit clause the process runs to conclusion without error. Would be nice to get an error message in sandbox.

This was selected as the best answer