ApexAdvancedbatchldvperformance
Process millions of records with Iterable batch instead of QueryLocator
Real World Scenario
QueryLocator on Custom_Log__c with 12M rows hits heap in start() when driving complex pre-filter logic unavailable in SOQL alone.
Expected Answer
• Database.Batchable<SObject> with Iterable<String> custom iterator
• Iterator fetches Id chunks via selective SOQL per iterator.next() call
• Avoid loading full QueryLocator scope into memory in start()
• Iterable batch for filtered sets from external Id list files
• Combine with AllowsCallouts when iterator drives external pagination
• Test iterator exhaust and empty iterator edge cases
• Monitor execute count matches expected chunks not iterator bugs
Follow-Up Questions & Answers
Click to expand — each follow-up includes a direct, interview-ready answer
Main difference: use case and scale. Database.Batchable<SObject> with Iterable<String> custom iterator. Iterator fetches Id chunks via selective SOQL per iterator.next() call. Pick based on your integration pattern and team capability. QueryLocator is default but Iterable batch solves heap and pre-filter problems at extreme volume. Optimize for scale and operational observability.
Architect Perspective
QueryLocator is default but Iterable batch solves heap and pre-filter problems at extreme volume.