1

Can anything help me with this error. when my instance doesn't show the following error

Method does not exist or incorrect signature: void schedule(String, String, BatchDeleteRecordChargeBack) from the type System

Class Batch

global class BatchDeleteRecordChargeBack implements Database.Batchable<sObject>,  Database.Stateful {
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        
        RangeDateCaseChargeback__c  RA =[SELECT Id,  StartDate__c, EndDate__c, testeDate__c from RangeDateCaseChargeback__c];
        
        String EndDate = RA.EndDate__c;
        string query = 'SELECT  id,  RecordType_Name__c, CreatedDate  from case where RecordType_Name__c =\'CBK\' AND CreatedDate = '+ EndDate +' limit 1';
        
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<SObject> caseList) {
        Database.delete(caseList, false);    
    }
    
    global void finish(Database.BatchableContext BC) {
        
    }
}

Schedule

global class ScheduleBatchableCDeleteChargeBack implements Schedulable {
    global void execute(SchedulableContext SC) {
        BatchDeleteRecordChargeBack batch01 = new BatchDeleteRecordChargeBack(); 
        String sch = '0 0 * * * ?';
        System.schedule('Schedule Job1', sch, batch01);
    }
}

2 Answers 2

1

If you want to run the batch every 30 minutes then follow the below steps.

  1. Open the Developer Console
  2. Go to Debug / Open Execute Anonymous Window
  3. Enter below code and execute it
ScheduleBatchableCDeleteChargeBack sb= new ScheduleBatchableCDeleteChargeBack();

String cronStr = '0 0,30 * * * *';

System.schedule('ScheduleBatchableCDeleteChargeBack Job', cronStr, sb);
1
2

Apex Scheduler documentation covers your situation

You can also use the Schedulable interface with batch Apex classes. The following example implements the Schedulable interface for a batch Apex class called batchable:

global class scheduledBatchable implements Schedulable {
   global void execute(SchedulableContext sc) {
      batchable b = new batchable(); 
      database.executebatch(b);
   }
}

You use System.schedule() to schedule an Apex class that implements Schedulable, but your scenario you'd be scheduling ScheduleBatchableCDeleteChargeBack which would then execute your batch.

There's also the System.scheduledBatch method if you don't want to have to have a class that implements schedulable execute it for you as shown above. In that case, the parameters are in a different order than the System.schedule() method

The System.scheduleBatch method takes the following parameters.

  • An instance of a class that implements the Database.Batchable interface.
  • The job name.
  • The time interval, in minutes, after which the job starts executing.
  • An optional scope value. This parameter specifies the number of records to pass into the execute method. Use this parameter when you have many operations for each record being passed in and are running into governor limits.
2
  • This way I work, the problem is that I need to run every 30 minutes in batch Jun 15, 2022 at 13:52
  • Yes, then you need to use the appropriate implementation. You'd schedule your ScheduleBatchableCDeleteChargeBack to run every 30 minutes using System.schedule(). ScheduleBatchableCDeleteChargeBack would then execute your batch class. Jun 15, 2022 at 14:17

You must log in to answer this question.

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