I have wrote a batch class and now i am writing test class for it but i am getting this error. Argument must be an object that implements Database.Batchable

Batch class

global class CBatchCalculateRatingsHistoricalData 
// Persistent variables
global Boolean hasErrors {get; private set;}

// Constructor
global CBatchCalculateRatingsHistoricalData()
    this.hasErrors = false;

global Database.QueryLocator start(Database.BatchableContext BC)
  system.debug('Processing start method'); 
    // Query string for batch Apex
    String query = ''; 
    query += 'SELECT Id,name,Date_of_First_Order__c,Number_of_Orders__c FROM Account ';
        query += ' LIMIT 200';
    return Database.getQueryLocator(query);

global void execute(Database.BatchableContext BC, List<sObject> objectBatch)


global void finish(Database.BatchableContext BC)


test class

@isTest(seeAllData = true)
public class scheduledBatchable
 static testMethod void Test_CBatchRatingsHistory()
     CBatchCalculateRatingsHistoricalData b = new CBatchCalculateRatingsHistoricalData();
     Database.executeBatch(b, 200);



please tell me what is the issue with this code. If i am wrong then please help me to get it right.

1 Answer 1


Your class has to implement the interface, so that the platform can cast it to Database.Batchable and pass it to the Database.executeBatch method (which requires a parameter of this type).

global class CBatchCalculateRatingsHistoricalData implements Database.Batchable<sObject>

Note: Also you no longer need to make the class and its methods global, unless you want to expose the class to code outside your package.

This is a really useful topic in the developers guide, it also covers best practices on testing Batch Apex.

You must log in to answer this question.