1

I need help in writing 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);
    } 

}
2

Browse other questions tagged or ask your own question.