You need to sign in to do that
Don't have an account?
Hemanth Neelapu
Test Class for Apex Schedulable batch procress
Hi Guys,
I need help in writing a test class for the below Apex Schedulable batch Process.
Can anyone help me out?
global class CLM_Batch_ExpireAgreements implements Database.Batchable<sObject>,Schedulable,Database.Stateful {
//Batch Start method
global Database.QueryLocator start(Database.BatchableContext BC) {
string Agreement_Status = 'Activated' ;
string strQuery='SELECT id,Apttus__Contract_End_Date__c , Apttus__Status__c , Apttus__Auto_Renewal__c ,Apttus__Status_Category__c FROM Apttus__APTS_Agreement__c';
strQuery+=' WHERE Apttus__Status__c = \'Activated\' and Apttus__Contract_End_Date__c < today and Apttus__Auto_Renewal__c = False' ;
system.debug(' febgdg'+ strQuery);
return Database.getQueryLocator(strQuery);
}
//Batch Execute method
global void execute(Database.BatchableContext BC, List<Apttus__APTS_Agreement__c> Scope) {
list<Apttus__APTS_Agreement__c> agr = new list<Apttus__APTS_Agreement__c>();
for(Apttus__APTS_Agreement__c agrObj : scope){
agrObj.Apttus__Status__c ='Expired' ;
agrObj.Apttus__Status_Category__c ='Expired' ;
agr.add(agrObj);
}
update agr;
}
//Batch Finish method
global void finish(Database.BatchableContext BC) {
}
//Method which schedules the batch
global void execute(SchedulableContext sc) {
CLM_Batch_ExpireAgreements snInstance = new CLM_Batch_ExpireAgreements ();
ID batchprocessid = Database.executeBatch(snInstance);
}
}
I need help in writing a test class for the below Apex Schedulable batch Process.
Can anyone help me out?
global class CLM_Batch_ExpireAgreements implements Database.Batchable<sObject>,Schedulable,Database.Stateful {
//Batch Start method
global Database.QueryLocator start(Database.BatchableContext BC) {
string Agreement_Status = 'Activated' ;
string strQuery='SELECT id,Apttus__Contract_End_Date__c , Apttus__Status__c , Apttus__Auto_Renewal__c ,Apttus__Status_Category__c FROM Apttus__APTS_Agreement__c';
strQuery+=' WHERE Apttus__Status__c = \'Activated\' and Apttus__Contract_End_Date__c < today and Apttus__Auto_Renewal__c = False' ;
system.debug(' febgdg'+ strQuery);
return Database.getQueryLocator(strQuery);
}
//Batch Execute method
global void execute(Database.BatchableContext BC, List<Apttus__APTS_Agreement__c> Scope) {
list<Apttus__APTS_Agreement__c> agr = new list<Apttus__APTS_Agreement__c>();
for(Apttus__APTS_Agreement__c agrObj : scope){
agrObj.Apttus__Status__c ='Expired' ;
agrObj.Apttus__Status_Category__c ='Expired' ;
agr.add(agrObj);
}
update agr;
}
//Batch Finish method
global void finish(Database.BatchableContext BC) {
}
//Method which schedules the batch
global void execute(SchedulableContext sc) {
CLM_Batch_ExpireAgreements snInstance = new CLM_Batch_ExpireAgreements ();
ID batchprocessid = Database.executeBatch(snInstance);
}
}
Try the following test-class, it may be helpful for you:
Batch-Class Test Class: I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha