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
SalesforceCrm AccountCRMSalesforceCrm AccountCRM 

Compilation Error Constructor not defined: [DeleteDownloadHitCountBatch].<Constructor>(String)

Can any one help me out with this error .When i compile all the classes , the system throws an error as :
Compilation Errors found:
DeleteDownloadHitOlderAYearSchedular: line 4, column 67: Constructor not defined: [DeleteDownloadHitCountBatch].<Constructor>(String)
Schedular Class is :
global class DeleteDownloadHitOlderAYearSchedular Implements Schedulable
{    
    global void execute(SchedulableContext sc) {
        DeleteDownloadHitCountBatch deleteDownloadHitCountBatch = new DeleteDownloadHitCountBatch('SELECT Id,Name FROM Download_Hit_Count__c WHERE CreatedDate < LAST_n_DAYS:365');
        Database.executeBatch(deleteDownloadHitCountBatch,100);           
    }
    
    
}
Batch Class :
global class DeleteDownloadHitCountBatch implements Database.Batchable<sObject>,Schedulable {
    
    global String query;
    
   /* global DeleteDownloadHitCountBatch(String q) {
        query = q;
    }*/
    
    global DeleteDownloadHitCountBatch() {
        query = 'SELECT Id,Name FROM Download_Hit_Count__c WHERE CreatedDate < LAST_n_DAYS:365';
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<sObject> scope){
        delete scope;
        //Database.emptyRecycleBin(scope);
    }
    
    global void finish(Database.BatchableContext BC){
    }
    
    //execute methode for scheduler
    global void execute(SchedulableContext sc) {
        DeleteDownloadHitCountBatch delDownloadHitCount = new DeleteDownloadHitCountBatch();
        Database.executeBatch(delDownloadHitCount ,200);           
    }
}
Any help very much appreciated.


 
Best Answer chosen by SalesforceCrm AccountCRM
DebasisDebasis
Hi SalesforceCrm AccountCRM,

in your batch class "DeleteDownloadHitCountBatch ", you have Zero argumnet constructor as below
global DeleteDownloadHitCountBatch() {
        query = 'SELECT Id,Name FROM Download_Hit_Count__c WHERE CreatedDate < LAST_n_DAYS:365';
    }
so when you will instantitae DeleteDownloadHitCountBatch class, you need to use this zero argumnet cosstructor but in your scheduled class you have used one argumnet construcor and parameter is a string(soql) as
DeleteDownloadHitCountBatch deleteDownloadHitCountBatch = new DeleteDownloadHitCountBatch('SELECT Id,Name FROM Download_Hit_Count__c WHERE CreatedDate < LAST_n_DAYS:365');
so this one argumnet constructor is not exist in your batch class, so you need to use only zero argumnent constructor for this as per below code. Anyways same soql you have already placed in your batch class constructor so no need to pass it again during instantiation of the batch class.
global class DeleteDownloadHitOlderAYearSchedular Implements Schedulable
{    
    global void execute(SchedulableContext sc) {
	//removed your soql parameter from here
        DeleteDownloadHitCountBatch deleteDownloadHitCountBatch = new DeleteDownloadHitCountBatch();
        Database.executeBatch(deleteDownloadHitCountBatch,100);           
    }
    
    
}


please let me know if you need further help.

Thanks,
Debasis
 

All Answers

Mahesh DMahesh D
Please take the below code:
 
global class DeleteDownloadHitOlderAYearSchedular Implements Schedulable
{    
    global void execute(SchedulableContext sc) {
        DeleteDownloadHitCountBatch deleteDownloadHitCountBatch = new DeleteDownloadHitCountBatch();
        Database.executeBatch(deleteDownloadHitCountBatch,100);           
    }
    
    
}

Please do let me know if it helps you.

Regards,
Mahesh
DebasisDebasis
Hi SalesforceCrm AccountCRM,

in your batch class "DeleteDownloadHitCountBatch ", you have Zero argumnet constructor as below
global DeleteDownloadHitCountBatch() {
        query = 'SELECT Id,Name FROM Download_Hit_Count__c WHERE CreatedDate < LAST_n_DAYS:365';
    }
so when you will instantitae DeleteDownloadHitCountBatch class, you need to use this zero argumnet cosstructor but in your scheduled class you have used one argumnet construcor and parameter is a string(soql) as
DeleteDownloadHitCountBatch deleteDownloadHitCountBatch = new DeleteDownloadHitCountBatch('SELECT Id,Name FROM Download_Hit_Count__c WHERE CreatedDate < LAST_n_DAYS:365');
so this one argumnet constructor is not exist in your batch class, so you need to use only zero argumnent constructor for this as per below code. Anyways same soql you have already placed in your batch class constructor so no need to pass it again during instantiation of the batch class.
global class DeleteDownloadHitOlderAYearSchedular Implements Schedulable
{    
    global void execute(SchedulableContext sc) {
	//removed your soql parameter from here
        DeleteDownloadHitCountBatch deleteDownloadHitCountBatch = new DeleteDownloadHitCountBatch();
        Database.executeBatch(deleteDownloadHitCountBatch,100);           
    }
    
    
}


please let me know if you need further help.

Thanks,
Debasis
 
This was selected as the best answer
SalesforceCrm AccountCRMSalesforceCrm AccountCRM
@Mahesh D,@Debasis :Thanks for your response.
Mahesh DMahesh D
Hi,

Is your problem resolved, if yes then please mark it as a resolved so that it will be helpful to others in the future.

Regards,
Mahesh