Skip to content

Instantly share code, notes, and snippets.

@dancinllama
Created July 24, 2012 18:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dancinllama/3171718 to your computer and use it in GitHub Desktop.
Save dancinllama/3171718 to your computer and use it in GitHub Desktop.
Batch Execution Page
/**
* P2_BatchProcessController
* @description VF controller class for a VF tab
* allowing user to select a batch / schedule apex job
* and execute it immediately
* @author dancinllama
* @date 4/17/2012
*/
public class P2_BatchProcessController {
//Member variables
private Map<String,Schedulable> schedulableClassMap {get;set;}
public String key {get;set;}
/**
* @description Default constructor
*/
public P2_BatchProcessController(){
batchableClassMap = new Map<String,Database.Batchable<sObject>>();
batchableClassMap.put('SSN Encryption',new P2_BatchCaseSSNEncryption());
batchableClassMap.put('Record Cleanup',new P2_BatchRecordCleanup());
}
/**
* @description returns list of select options
* with batchable class description for name and value
* @return List<SelectOption> list of select options of Batchable classes to execute
*/
public List<SelectOption> selectOptions{
get{
List<SelectOption> selectOptions = new List<SelectOption>();
for(String key : batchableClassMap.keySet()){
selectOptions.add(new SelectOption(key,key));
}
return selectOptions;
}
}
/**
* @description Execute action, executes
* the batchable class manually
* @return null PageReference
*/
public PageReference execute(){
if(key != null){
//Put whatever your schedule is in cron format... this is 15th min of every hour
System.schedule('Job2', '0 15 * * * ?', batchableClassMap.get(key));
//Database.executeBatch(batchableClassMap.get(key));
}
return null;
}
}
<!-- Called via a VF tab for Administering / Executing Batch jobs -->
<apex:page controller="P2_BatchProcessController">
<apex:form id="theform">
<apex:pageBlock >
<apex:pageBlockSection title="{!$Label.AdminTab_Title}" columns="1">
<apex:pageBlockSectionItem >
<apex:outputPanel >
<apex:outputLabel for="selectList" value="{!$Label.AdminTab_Select}" />
</apex:outputPanel>
<apex:outputPanel >
<apex:selectList value="{!key}" size="1" multiselect="false">
<apex:selectOptions value="{!selectOptions}" />
</apex:selectList>&nbsp;
<apex:commandButton value="{!$Label.AdminTab_Execute}" action="{!execute}" status="estatus" rerender="theform"/>
<apex:actionStatus id="estatus" startText="{!$Label.AdminTab_Processing}" />
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment