+ Start a Discussion

What is the difference between Custom Iterators and batch apex with batch size 1?

ANUTEJANUTEJ (Salesforce Developers) 
Hi Priyanka,

In batch apex, it is meant to be used with large number of records and batch size 1 is not the recommended way to use it, and as mentioned in the link https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_iterable.htm#:~:text=To%20use%20custom%20iterators%2C%20you,that%20implements%20the%20Iterator%20interface.&text=Returns%20true%20if%20there%20is,collection%20being%20traversed%2C%20false%20otherwise.&text=Returns%20the%20next%20item%20in,declared%20as%20global%20or%20public%20. we can create a custom iterator and use it in conjunction with batch apex.

you can try looking at this trailhead module to learn more about batch apex: https://trailhead.salesforce.com/content/learn/modules/asynchronous_apex/async_apex_batch

I hope this helps and in case if this comes handy can you please choose this as the best answer so that it can be useful for others in the future.