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
softcloud2009softcloud2009 

For Loop using List<>

Hi All,

 

I would like to understand why For loop with List<> is more efficient than regular loop:

 

for (List<Account> accts : [query statement]

 

is more efficient than

 

for (Account accts : [query statement]

 

Can anyone help me to understand why??

 

Thanks.

patrospatros

I think the biggest efficiency is if you are doing DML within the for loop. You can maintain a List of objects, work over them, and do an upsert en masse.

 

Based on this documentation, it sounds like they are otherwise the same...