Created
January 29, 2020 05:29
-
-
Save srujan21/02b713350178f02dd115fceec9f92059 to your computer and use it in GitHub Desktop.
A Template for writing Scheduled Batch job in apex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @File Name : CreateMissingContactUserLinkController.cls | |
* @Description : | |
* @Author : | |
* @Group : | |
* @Last Modified By : | |
* @Last Modified On : 2020-01-29 15:32:43 | |
* @Modification Log : | |
* Ver Date Author Modification | |
* 1.0 2020-01-29 Srujan Initial Version | |
**/ | |
public class CreateMissingContactUserLinkController implements Database.Batchable<sObject>, Database.Stateful, Schedulable{ | |
public void execute(SchedulableContext sc) { | |
CreateMissingContactUserLinkController linkCU = new CreateMissingContactUserLinkController(); | |
Database.executeBatch(linkCU, 200); | |
} | |
/** | |
* @description | |
* @author | |
* @param Database.BatchableContext BC | |
* @return database.querylocator | |
**/ | |
public database.querylocator start(Database.BatchableContext BC) { | |
//Query all target records | |
String query = 'SELECT id, studentportalUser__c, Pidm__c FROM Contact WHERE recordtype.name = \'studentrecord\' AND studentportaluser__c = null AND status__c IN (\'TB\', \'AS\') limit 500'; | |
return Database.getQueryLocator(query); | |
} | |
/** | |
* @description | |
* @author | |
* @param Database.BatchableContext BC | |
* @param List<Contact> contacts | |
* @return void | |
**/ | |
public void execute(Database.BatchableContext BC, List<sObject> scope) { | |
// Iterate in Scope and perform main logic | |
} | |
/** | |
* @description finish method of Standard Batch class | |
* @author | |
* @param Database.BatchableContext BC | |
* @return void | |
**/ | |
public void finish(Database.BatchableContext BC) { | |
/*AsyncApexJob apexJob = [Select Id, Status, NumberOfErrors, JobItemsProcessed, | |
TotalJobItems, ExtendedStatus | |
from AsyncApexJob where Id = :BC.getJobId()]; | |
if(apexJob.NumberOfErrors > 0) { | |
string subject = 'Import integration entires To Opportunity Batch ' + apexJob.Status + ' with ' + apexJob.NumberOfErrors + ' failures.'; | |
string body = 'The batch Apex job processed ' + apexJob.TotalJobItems + | |
' batches with ' + apexJob.NumberOfErrors + ' failures. Status details: ' + apexJob.ExtendedStatus; | |
}*/ | |
} | |
/** | |
* @description | |
* @author | |
* @return void | |
**/ | |
public static void scheduleIt(){ | |
/*ReadArtezTransactions m = new ReadArtezTransactions(); | |
String sch = '0 0 0/1 1/1 * ? *'; | |
String jobName = (Test.isRunningTest() ? 'Read Artez Integration Entry Test' : 'Read Artez Integration Entry'); | |
String jobID = system.schedule(jobName , sch, m);*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment