Skip to content

Instantly share code, notes, and snippets.

@cdcarter
Last active March 12, 2016 21:39
Show Gist options
  • Save cdcarter/026a8012ba5be8678d9f to your computer and use it in GitHub Desktop.
Save cdcarter/026a8012ba5be8678d9f to your computer and use it in GitHub Desktop.
SuperBatch
// a batch class for every context, by @cdcarter
public class SuperBatch implements Database.Batchable<SObject>, Schedulable {
// from anon apex, `SuperBatch.startBatch()` starts the job with batch size 100
public static void startBatch() { (new SuperBatch()).doIt(); }
public SuperBatch() {}
public void doIt() { Database.executeBatch(this,100); }
/* create a visualforce page below, and a list button
* add the list button to list views to ondemand run the batch (size 100)
* <apex:page standardController="SObject" recordSetVar="sobj"
* extensions="SuperBatch" action="{!batch}"></apex:page> */
public PageReference batch() { doIt(); return new PageReference('/');}
public SuperBatch(ApexPages.StandardSetController ssc) {}
// allows the class to be scheduled as schedulable apex for overnight run
public void execute(SchedulableContext sc) { doIt(); }
// your batch logic below!
public Iterable<SObject> start(Database.BatchableContext bc) {return null;}
public void execute(Database.BatchableContext bc,List<SObject> l) {}
public void finish(Database.BatchableContext bc) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment