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
neshnesh 

please help me---Constructor not defined when testing batchable class

I am getting the error:Constructor not defined when testing batchable class-----test class line

apex test class:

@isTest
public class  testSendeMailinBatch {

Public static testMethod void m3(){  
    Database.QueryLocator QL;
        Database.BatchableContext BC;
        List<SEOX3_Client__c> CL = new List<SEOX3_Client__c>();
        SendeMailinBatch smb=new SendeMailinBatch();----Error: Compile Error: Constructor not defined: [SendeMailinBatch].<Constructor>() at line
        Database.QueryLocatorIterator QIT =  QL.iterator();
              QL = smb.start(bc);
         smb.execute(BC,CL);
        smb.finish(BC);
        }

}

----------------------------------------------------------------------------------------------------------------------------------------------------

Batch apex class:

global class SendeMailinBatch implements Database.Batchable<sObject>,Database.Stateful  
{  
 public list <SEOX3_Client__c> lstcl;
 public string mbody;
 public string msubject;
 public string mfromadd;
 public string mccadd;
 
global SendeMailinBatch(list<SEOX3_Client__c> l1, string body, string fromadd, string ccadd, string subject)  
       {  
             mbody = body;
             msubject = subject;
             mfromadd = fromadd;
             mccadd = ccadd;
             lstcl = l1;
             system.debug('***ccemailcalled*****'+mccadd);
     
      
       }
global Database.QueryLocator start(Database.BatchableContext BC)  
   {  
       
      String query = 'SELECT id,e_mail__c, Sales_Rep_E_Mail__c,CC__c,SUBJECT__c,body2__c FROM SEOX3_Client__c where id in :lstcl';
      return Database.getQueryLocator(query);
     
   }
  global void execute(Database.BatchableContext BC, List<sObject> scope)  
   {  
       for(Sobject s : scope)  
         {
            SEOX3_Client__c CM = (SEOX3_Client__c)s ;  
            string[] c2 = new String[] {mccadd};
            if(mccadd!=NULL && mccadd.trim() != '')
                     {
                        c2=mccadd.split(',', 0);
     
                      }
              else
                      {
                          c2=NULL;
                      }
                        
                   String[] toAddresses = new String[] {cm.E_Mail__c};
                   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                   mail.setToAddresses(toAddresses);        
                   mail.setSubject(msubject);
                   mail.setCcAddresses(c2);
                   mail.setPlainTextBody(mbody);
                   Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail });
          }
                    
         
      }  
    
 
  global void finish(Database.BatchableContext BC)  
       {  
      
       }  
}

------------------------------------

Best Answer chosen by Admin (Salesforce Developers) 
LakshmanLakshman

Modify your test class as below:

 

@isTest
public class  testSendeMailinBatch {

Public static testMethod void m3(){  

        
        SEOX3_Client__c s = new SEOX3_Client__c();
        s.Name = 'Test';//If Not Autonumber
        //Fill other fields of SEOX3_Client__c  sObjectwith test values
        insert s;//Insert it
        List<SEOX3_Client__c> CL = new List<SEOX3_Client__c>();
        CL.add(s);
        SendeMailinBatch smb=new SendeMailinBatch(CL, 'Test Body', 'testerfrom@testemail.com', 'testercc@testemail.com','Test Subject');//Define the parameterized constructor of batch class
        Test.startTest();
        Database.executeBatch(smb,1);
        Test.stopTest();
        }

}

 

Please accept it as an answer if it helps you.

 

-Lakshman

 

All Answers

LakshmanLakshman

Modify your test class as below:

 

@isTest
public class  testSendeMailinBatch {

Public static testMethod void m3(){  

        
        SEOX3_Client__c s = new SEOX3_Client__c();
        s.Name = 'Test';//If Not Autonumber
        //Fill other fields of SEOX3_Client__c  sObjectwith test values
        insert s;//Insert it
        List<SEOX3_Client__c> CL = new List<SEOX3_Client__c>();
        CL.add(s);
        SendeMailinBatch smb=new SendeMailinBatch(CL, 'Test Body', 'testerfrom@testemail.com', 'testercc@testemail.com','Test Subject');//Define the parameterized constructor of batch class
        Test.startTest();
        Database.executeBatch(smb,1);
        Test.stopTest();
        }

}

 

Please accept it as an answer if it helps you.

 

-Lakshman

 

This was selected as the best answer
neshnesh

Thanks for sharing your knowledge.Its cover 96%.