You need to sign in to do that
Don't have an account?
Mayuri Deshmukh 3
How to write test class for below code of deleting lead
Hi, I have written below batch class how can I write test class for this
code:-
global class DeleteLeads_Batch implements Database.Batchable<sObject> {
Id rtid = RecordTypeUtil.getRecordTypeIdByDevName('Lead','Digital_Marketing');
String query = 'select id, Status, recordtype.name from Lead where recordTypeid = rtid AND (LastModifiedDate > LAST_N_DAYS:180 OR Status like \'%Closed%\'';
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC,List<Lead> leadList){
delete leadList;
}
global void finish(Database.BatchableContext BC){
System.debug('Job Finished');
}
}
Thanks,
Mayuri
code:-
global class DeleteLeads_Batch implements Database.Batchable<sObject> {
Id rtid = RecordTypeUtil.getRecordTypeIdByDevName('Lead','Digital_Marketing');
String query = 'select id, Status, recordtype.name from Lead where recordTypeid = rtid AND (LastModifiedDate > LAST_N_DAYS:180 OR Status like \'%Closed%\'';
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC,List<Lead> leadList){
delete leadList;
}
global void finish(Database.BatchableContext BC){
System.debug('Job Finished');
}
}
Thanks,
Mayuri
What is the error you are getting?
also, small obervation... are you trying to delete the all the closed leads?
Yes I am deleting all the closed leads whose recordtype is Digital-Marketing and I am not getting error code is fine.
I wanted to know how can I write test class for this batch class.
can you please help me in doing that?
Thanks,
Mayuri
Can you try the below test class.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,