0

I'm scheduling a batchable class that deletes records from a custom object. The test class for my scheduled class saves without errors. However, I'm getting a "Constructor not defined: [deleteEndpointLogs].()" error when saving the test class for the batchable class and am getting stumped on how to resolve it.

Here is the code for the batch class:

global class deleteEndpointLogs implements Database.Batchable<sObject>{
   global final String Query;
   global deleteEndpointLogs(String q){
    Query=q;
}

global Database.QueryLocator start(Database.BatchableContext BC){
    return Database.getQueryLocator(query);
}

global void execute(Database.BatchableContext BC,List<Endpoint_Log__c> scope){
    delete scope;
}

global void finish(Database.BatchableContext BC){}

}

And here is my test class:

@isTest 
public class deleteEndpointLogsTest 
{
    static testMethod void testMethod1() 
    {
        List<Endpoint_Log__c> logList= new List<Endpoint_Log__c>();
        for(Integer i=0 ;i <200;i++)
        {
            Endpoint_Log__c log = new Endpoint_Log__c();
            log.Resource_Name__c ='Test'+i;
            logList.add(log);
        }
        
        insert logList;
        
        Test.startTest();

            deleteEndpointLogs batch = new deleteEndpointLogs();
            DataBase.executeBatch(batch); 
            
        Test.stopTest();
    }
}

The error is on line 18 of the test class. Any help with getting this resolved is greatly appreciated.

1 Answer 1

3

Your batch class does not contain a no-argument constructor, which you call here:

        deleteEndpointLogs batch = new deleteEndpointLogs();
        

Your constructor requires an argument, a query string:

global deleteEndpointLogs(String q){

It looks like you'll want to pass a query like SELECT Id FROM Endpoint_Log__c LIMIT 100, which will allow you to write assertions to validate that your class is deleting exactly as much as you asked it to delete and leaving other records unaltered.

3
  • Thanks David, really appreciate the response. I added this to my test class (right after Test.stopTest(); but still encountering the same error: Endpoint_Log__c epl = [SELECT ID FROM Endpoint_Log__c WHERE CreatedDateapextesting__c < LAST_N_DAYS:7 AND Resource_name__c != 'OpportunityResource' AND Processed__c = FALSE LIMIT 100]; System.assert(epl.Id != null); Is something off with my assertion? Dec 19, 2020 at 1:07
  • Did you also fix the constructor call?
    – David Reed
    Dec 20, 2020 at 20:34
  • Ah, missed that important detail. Got it all sorted now. Thanks for your help! Dec 22, 2020 at 6:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .