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
Mak OneMak One 

Will this custom iterator will work as batch only if used by batch. Like taking 200 records at a time. Or will take all records at once

global class CustomIterable
   implements Iterator<Account>{

   List<Account> accs {get; set;}
   Integer i {get; set;}

   public CustomIterable(){
       accs =
       [SELECT Id, Name,
       NumberOfEmployees
       FROM Account
       WHERE Name = 'false'];
       i = 0;
   }  

   global boolean hasNext(){
       if(i >= accs.size()) {
           return false;
       } else {
           return true;
       }
   }   

   global Account next(){
       // 8 is an arbitrary
       // constant in this example
       // that represents the
       // maximum size of the list.
       //if(i == 8){return null;}
       i++;
       return accs[i-1];
   }
}

I have taking this from example and commented line: if(i == 8){return null;}
What this line is for?

Also below statement in constructor:
accs =
       [SELECT Id, Name,
       NumberOfEmployees
       FROM Account
       WHERE Name = 'false'];

will NOT select all records at once? If it fetches all records at once then there is no sense of using custom Iterator in Batch class.
Hargobind_SinghHargobind_Singh
(Taken from another forum post):

You can also pass data into a batch using a custom iterator - in that case, you create the set of records to be processed via some custom programming, and the batch will not reduce the number to a maximum of 2000 records per execution, but all other governor limits still apply, so you would need to allow for that with any DML you execute.

It seems like you are using a SOQL directly to fill up a list, so the number of records inserted might be restricted, however, you can try to use a for-loop and query to get more records, fill your own collection and pass to batch ? 

Here is the related post that I was reading through as well: https://developer.salesforce.com/forums/ForumsMain?id=906F00000008yVOIAY