function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mark TMmark TM 

Test lass Help Needed pls

Hi ,

 

Please help me to write a test class for the below batch class written,

 

global class logdeletion implements Database.Batchable<sObject>{
    public String query{get;set;}
    public String email{get;set;}
    //public Id toUserId{get;set;}
   // public Id fromUserId{get;set;}
    
    global Database.querylocator start(Database.BatchableContext BC){
        return Database.getQueryLocator('Select Comments__c,Name,Owner,CreatedBy,LastModifiedBy,Date_TimeStamp__c,isSuccess__c,Report_URL__c,Result_String__c,Sample_Id__c,Sample_Stage__c FROM Log__c' );
    }
    
    global void execute(Database.BatchableContext BC, List<sObject> scope){
        List<Log__c> Logs = new List<Log__c>();
        
        for(sObject s : scope){
            Log__c a = (Log__c)s;
            
        }        
        delete Logs ;   
        //system.debug('batch apex called'+accns);     
    }
    global void finish(Database.BatchableContext BC){
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        mail.setToAddresses(new String[] {email});
        mail.setReplyTo('test@test.com');
        //mail.setSenderDisplayName('SFDC Developer Organization');
        //mail.setSubject('Batch Process');
        //mail.setPlainTextBody('Batch Process has completed');
        
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }

 

 


}Thanks

bob_buzzardbob_buzzard

What does your test class look like at the moment? How much coverage do you have?

mark TMmark TM

This is the test class i have written ,

 

@isTest
private class Testlogdeletion  {
    
    static testMethod void TestClass_logdeletion() {
     Test.startTest();
   List<Log__c> st=new List<Log__c>();
   Database.BatchableContext bc;
   logdeletion obj=new logdeletion();
      st=obj.start(bc);
     Test.stopTest();
    }

}

 

i am getting constructor not defined, not able to proceed further, need ur help

 

 

 

this is my batch class

 

global class logdeletion implements Database.Batchable<sObject>{
    public String query{get;set;}
    public String email{get;set;}
    
   // public logdeletion(){
    // }
    //public Id toUserId{get;set;}
   // public Id fromUserId{get;set;}
    // constructor
   global logdeletion (string query) {
       this.query = query;
   }
    
    global Database.querylocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<sObject> scope){
        List<Log__c> Logs = new List<Log__c>();
        
        for(sObject s : scope){
         Log__c a = (Log__c)s;
         Logs.add(a);
        }        
        delete Logs ;   
        //system.debug('batch apex called'+accns);     
    }
    global void finish(Database.BatchableContext BC){
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        mail.setToAddresses(new String[] {email});
        mail.setReplyTo('jayabalan.jayaraman@techmahindra.com');
        //mail.setSenderDisplayName('SFDC Developer Organization');
        //mail.setSubject('Batch Process');
        //mail.setPlainTextBody('Batch Process has completed');
        
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
}

bob_buzzardbob_buzzard

In your test class you are trying to use a no-argument constructor, but you have only defined a constructor that takes a query.