Skip to content

Instantly share code, notes, and snippets.

@swapnilshrikhande
Last active May 7, 2020 09:49
Show Gist options
  • Save swapnilshrikhande/ea217b8cc9c83d59b5cead90246f50b2 to your computer and use it in GitHub Desktop.
Save swapnilshrikhande/ea217b8cc9c83d59b5cead90246f50b2 to your computer and use it in GitHub Desktop.
Apex Batch Class Template
/**
* @File Name : CreateMissingContactUserLinkController.cls
* @Description :
* @Author :
* @Group :
* @Last Modified By :
* @Last Modified On : 2020-01-29 15:32:43
* @Modification Log :
* @Param
* @Return
* Ver Date Author Modification
* 1.0 2020-01-29 Srujan Initial Version
**/
public class OpportunityBatchable implements Database.Batchable<sObject> {
/**
* <Explain Method Here>
* @author
* @param Database.BatchableContext batchableContext
* @return Database.QueryLocator
* /
public Database.QueryLocator start(Database.BatchableContext batchableContext) {
return Database.getQueryLocator(getQuery());
}
/**
* <Explain Method Here>
* @author
* @param Database.BatchableContext batchableContext,List<Opportunity> opportunityList
* @return void
* /
public void execute( Database.BatchableContext batchableContext
, List<Opportunity> opportunityList) {
/***re-query the database***/
opportunityList = Database.query(getQuery(opportunityList));
if(!opportunityList.isEmpty()){
//Buisness logic which updates the opportunity status
//BusinessLogic.processOpportunities(opportunityList);
system.debug(opportunityList);
}
}
/**
* <Explain Method Here>
* @author
* @param Database.BatchableContext batchableContext
* @return Database.QueryLocator
* /
private String getQuery(){
return getQuery(null);
}
/**
* <Explain Method Here>
* @author
* @param List<SObject>
* @return String - Query
* /
private String getQuery(List<Opportunity> opportunityList){
String query = ' Select Id'
+' From '+ Schema.SobjectType.Opportunity.Name
+' Where '+ Opportunity.Amount +' > :TARGET_AMOUNT'
+' AND '+ Opportunity.StageName +' IN :OPPORTUNITY_STAGE_OPEN';
if(null!=opportunityList && !opportunityList.isEmpty()){
query+= ' AND Id IN :opportunityList';
}
return query;
}
/**
* <Explain Method Here>
* @author
* @param Database.BatchableContext batchableContext
* @return void
* /
public void finish(Database.BatchableContext batchableContext) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment