+ Start a Discussion
Ken_KoellnerKen_Koellner 

"For loop list batch size" limit of 200, what is it?

I know many of the limits in Apex have either been raised or removed.  But "For loop list batch size" is still listed as 200.

 

Anyone know exactly what the limit is?  It isn't clearly defined anywhere . 

 

It seems to me I've had lists > 200 processed in a for lopp.  Also, I don't think you need the nested for loop when fetching > 200 items from a SOQL query any more.

 

So, what is it?

 

bob_buzzardbob_buzzard

My understanding is that this is the limit when carrying out a SOQL for loop of the form:

 

 

for (account[] accs : [select id from account])
{
   for (Account acc : accs)
   {
   }
}

 

which allows you to step through the results in discrete batches.  This is still recommended approach if you need to use DML on the resulting records, but I suspect that's an oversight, as the 200 record limit on a single DML operation has been upped to 1000 records these days.

 

 

 

Ken_KoellnerKen_Koellner

I don' think you have to do that anymore.

 

Try this code--

 

list<account>acctList = [select id from account limit 1000];
for (account acct : acctList) {
 System.debug(acct.id);
}

 

 

I ran that anonymously in the System Log window and it worked just fine.

 

 

bob_buzzardbob_buzzard

I know.  Hence I said in my post that I suspect the DML recommendation is an oversight.  

 

However, should you choose to carry out a batched SOQL for loop, the maximum batch size will be 200.  

 

I can't see any reason to use batched SOQL for loops, as a list can accommodate the maximum 10,000 records that a SOQL query will return.

 

 

Pari M 28Pari M 28
I believe the reason is heap size that would cause an issue. That is the only reason I can think of for using batched SOQL for loops.