Skip to content

Instantly share code, notes, and snippets.

@manzanit0
Created October 23, 2017 12:50
Show Gist options
  • Select an option

  • Save manzanit0/ff1fa64f8c8f696d3e3e132fa8864c17 to your computer and use it in GitHub Desktop.

Select an option

Save manzanit0/ff1fa64f8c8f696d3e3e132fa8864c17 to your computer and use it in GitHub Desktop.
Quick implementation of an Apex Batch, from the docs.
global class SearchAndReplace implements Database.Batchable<sObject>{
global final String Query;
global final String Entity;
global final String Field;
global final String Value;
global SearchAndReplace(String q, String e, String f, String v){
Query=q; Entity=e; Field=f;Value=v;
}
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> scope){
for(sobject s : scope){
s.put(Field,Value);
}
update scope;
}
global void finish(Database.BatchableContext BC){
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment