You need to sign in to do that
Don't have an account?

Please anyone write the Test Class
Hi
global class batchDeleteEndUser implements Schedulable
{
public static String CRON_EXP = '0 0 12 1 1/3 ? *';
global static String scheduleIt() {
batchDeleteEndUser delbatch = new batchDeleteEndUser();
return System.schedule('Delete EndUser Batch', CRON_EXP, delbatch);
}
global void execute(SchedulableContext sc) {
Datetime days = system.now().addDays(-365);
List<EndUser__c> objectList = new List<EndUser__c>();
for (EndUser__c EUser: [
select Id,name
from EndUser__c
where Id not in (select End_User__c from Case where status != 'Closed') and ((Time_of_Last_Created_Case__c<= :days and Time_of_Last_Initiated_Chat__c<=:days ) or (Time_of_Last_Created_Case__c=null and Time_of_Last_Initiated_Chat__c<=:days) or (Time_of_Last_Created_Case__c<= :days and Time_of_Last_Initiated_Chat__c=null))
]) {
objectList.add(EUser);
}
if (!objectList.isEmpty()) {
delete objectList;
system.debug('enduser----'+objectList);
}
}
}
Hi any one write the test class for above class its very urgent please---------------------
Thanks for Advance
Raj
global class batchDeleteEndUser implements Schedulable
{
public static String CRON_EXP = '0 0 12 1 1/3 ? *';
global static String scheduleIt() {
batchDeleteEndUser delbatch = new batchDeleteEndUser();
return System.schedule('Delete EndUser Batch', CRON_EXP, delbatch);
}
global void execute(SchedulableContext sc) {
Datetime days = system.now().addDays(-365);
List<EndUser__c> objectList = new List<EndUser__c>();
for (EndUser__c EUser: [
select Id,name
from EndUser__c
where Id not in (select End_User__c from Case where status != 'Closed') and ((Time_of_Last_Created_Case__c<= :days and Time_of_Last_Initiated_Chat__c<=:days ) or (Time_of_Last_Created_Case__c=null and Time_of_Last_Initiated_Chat__c<=:days) or (Time_of_Last_Created_Case__c<= :days and Time_of_Last_Initiated_Chat__c=null))
]) {
objectList.add(EUser);
}
if (!objectList.isEmpty()) {
delete objectList;
system.debug('enduser----'+objectList);
}
}
}
Hi any one write the test class for above class its very urgent please---------------------
Thanks for Advance
Raj
Please let us know if this will help you.
Thanks,
Amit Chaudhary
All Answers
Hello,
Please try with below test class.
Thanks & Cheers,
Jigar(pateljb90@gmail.com)
Please let us know if this will help you.
Thanks,
Amit Chaudhary
Pls try this below code
@isTest
public class BatchDeleteEndUserTest
{
static testMethod void TestBatchDeleteEndUser()
{
Test.startTest();
// Create End User data here, please update that as per your object and fields
EndUser__c objEndUser = new EndUser__c();
objEndUser.Name = 'Test End User';
Insert objEndUser;
batchDeleteEndUser.scheduleIt();
batchDeleteEndUser obj = new batchDeleteEndUser();
String chron = '0 0 23 * * ?';
System.schedule('testScheduledApex', chron, obj);
Test.stopTest();
}
}
If you get the answer, please mark it as the correct answer. It will be a help to others who are facing the same problem later.
Regards
Eswar Prasad
I have onemore doubt is without calling Cron Method How can i cover code coverage in execute method it is possible .
Regards
Raj
batchDeleteEndUser delbatch = new batchDeleteEndUser();
Database.executeBatch(delbatch ,200);