Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. public class MyBatchable implements Iterator<Integer>, Iterable<Integer>, Database.Batchable<Integer>, Database.Stateful, Database.AllowsCallouts {
  2. @TestVisible Integer remainingCount = 5000;
  3. public integer next() {
  4. return remainingCount--;
  5. }
  6. public boolean hasNext() {
  7. return remainingCount > 0;
  8. }
  9. public iterator<integer> iterator() {
  10. return this;
  11. }
  12. public Iterator<Integer> start(Database.BatchableContext bc) {
  13. return this;
  14. }
  15. public void execute(Database.BatchableContext bc, Integer[] values) {
  16. // Do your stuff here
  17. // If you run out of stuff to do, System.abortJob(bc.getJobId());
  18. }
  19. public void finish(Database.BatchableContext bc) {
  20. // Be sure to reset remainingCount if you need to process more data,
  21. // or you'll enter an infinite batch loop.
  22. // You can call another Database.executeBatch(this, 1); here if you need more processing.
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement