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
Anu Raj.ax1269Anu Raj.ax1269 

Argument must be an object that implements Database.Batchable

Hi,

 

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 ';
    if(system.Test.isRunningTest())
        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()
  {
      System.Test.startTest();
     CBatchCalculateRatingsHistoricalData b = new CBatchCalculateRatingsHistoricalData();
     Database.executeBatch(b, 200);
     System.Test.stopTest();

 }

 }

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

 

Thanks

Anu

Vinit_KumarVinit_Kumar

Hey Anu,

 

Try below code :-

 

@isTest(seeAllData = true)
public class scheduledBatchable
{
static testMethod void Test_CBatchRatingsHistory()
{
String query = 'SELECT Id,name,Date_of_First_Order__c,Number_of_Orders__c FROM Account';
List<Account> accList = new List<Account>();

for (Integer i=0;i<200;i++) {
Account acc = new Account(
Name='Test Account' + i);
accList.add(acc);
}
insert accList;

System.Test.startTest();
CBatchCalculateRatingsHistoricalData b = new CBatchCalculateRatingsHistoricalData();
Database.executeBatch(b, 200);
System.Test.stopTest();

}

}

priyaforsfdcpriyaforsfdc
hai anu i am on it as i have same problem.
SAKTHIVEL MSAKTHIVEL M

Hi,

 

In your apex class add the (implements Database.Batchable<sObject>) line,

 

like

 

global class CBatchCalculateRatingsHistoricalData implements Database.Batchable<sObject> {

//your code

 

for more info read theblogreaders.com