Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyBatchable implements Iterator<Integer>, Iterable<Integer>, Database.Batchable<Integer>, Database.Stateful, Database.AllowsCallouts {
- @TestVisible Integer remainingCount = 5000;
- public integer next() {
- return remainingCount--;
- }
- public boolean hasNext() {
- return remainingCount > 0;
- }
- public iterator<integer> iterator() {
- return this;
- }
- public Iterator<Integer> start(Database.BatchableContext bc) {
- return this;
- }
- public void execute(Database.BatchableContext bc, Integer[] values) {
- // Do your stuff here
- // If you run out of stuff to do, System.abortJob(bc.getJobId());
- }
- public void finish(Database.BatchableContext bc) {
- // Be sure to reset remainingCount if you need to process more data,
- // or you'll enter an infinite batch loop.
- // You can call another Database.executeBatch(this, 1); here if you need more processing.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement