You need to sign in to do that
Don't have an account?
Sid Lightning
Need help in writting Test class for batc Class
Hi,
I need help in writting test class for below written batch class.
Can anyone help please?
global class UpdateCurrentMonth implements Database.Batchable<sObject>,Schedulable, Database.stateful
{
global void execute(SchedulableContext sc)
{
}
global Database.queryLocator start(Database.BatchableContext BC )
{
String str = 'SELECT Id, Start_Date__c,End_Date__c,Current_Month__c FROM Business_Re_development_Target__c';
return Database.getQueryLocator(str);
}
global void execute(Database.BatchableContext BC, List<Business_Re_development_Target__c> BRTToProcess)
{
List<Business_Re_development_Target__c> BRTList = new List<Business_Re_development_Target__c>();
for(Business_Re_development_Target__c BRTObj : BRTToProcess){
If(Date.Today().Year() == BRTObj.End_Date__c.Year()){
If(Date.Today().Month() > BRTObj.End_Date__c.month())
{
BRTObj.Current_Month__c = False;
BRTList.add(BRTObj);
}
}
else
If(Date.Today().Year() > BRTObj.End_Date__c.Year()){
If(Date.Today().Month() < BRTObj.End_Date__c.month())
{
BRTObj.Current_Month__c = False;
BRTList.add(BRTObj);
}
}
}
update BRTList;
}
global void finish(Database.BatchableContext BC)
{
system.debug('finish');
}
}
I need help in writting test class for below written batch class.
Can anyone help please?
global class UpdateCurrentMonth implements Database.Batchable<sObject>,Schedulable, Database.stateful
{
global void execute(SchedulableContext sc)
{
}
global Database.queryLocator start(Database.BatchableContext BC )
{
String str = 'SELECT Id, Start_Date__c,End_Date__c,Current_Month__c FROM Business_Re_development_Target__c';
return Database.getQueryLocator(str);
}
global void execute(Database.BatchableContext BC, List<Business_Re_development_Target__c> BRTToProcess)
{
List<Business_Re_development_Target__c> BRTList = new List<Business_Re_development_Target__c>();
for(Business_Re_development_Target__c BRTObj : BRTToProcess){
If(Date.Today().Year() == BRTObj.End_Date__c.Year()){
If(Date.Today().Month() > BRTObj.End_Date__c.month())
{
BRTObj.Current_Month__c = False;
BRTList.add(BRTObj);
}
}
else
If(Date.Today().Year() > BRTObj.End_Date__c.Year()){
If(Date.Today().Month() < BRTObj.End_Date__c.month())
{
BRTObj.Current_Month__c = False;
BRTList.add(BRTObj);
}
}
}
update BRTList;
}
global void finish(Database.BatchableContext BC)
{
system.debug('finish');
}
}
Please try the below test class:
Thanks,
Maharajan.C