I have created below batch apex class. I have also created test class for this. But this test class is only covering 27% of batch apex class. Also, it is not calling execute method of batch apex class.
Batch Apex class:
global class LeadDuplicateRemove implements Database.Batchable < sObject > {
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator('select Id, CreatedDate, Phone, Status, Email from Lead Where convertedbusiness__c != null and LeadAudit__c = null and isDeleted = false order by CreatedDate ASC Limit 1');
}
global void execute(Database.BatchableContext bc, List < Lead > scope) {
for (Lead lead: scope) {
Database.QueryLocator leadQueryLocator = Database.getQueryLocator([Select Id, CreatedDate, Phone, Status, Email from Lead where convertedbusiness__c != null and LeadAudit__c = '1' and isDeleted = false order by CreatedDate ASC Limit 1]);
Database.QueryLocatorIterator iterator = leadQueryLocator.iterator();
while (iterator.hasNext()) {
Lead leadObj = (Lead) iterator.next();
if(lead.ConvertedBusiness__c == leadObj.ConvertedBusiness__c){
lead.ConvertedBusiness__c = null;
}
}
}
}
global void finish(Database.BatchableContext bc) {
}
}
Test class:
@isTest global class LeadDuplicateRemoveTest {
@testSetup
global static void setup() {
Lead lead1 = new Lead(LastName='testlead1 ', RAF_Nurture_Campaign__c = 'None',
company='test', Email='[email protected]',Phone = '1111111111',Status ='Completed');
insert lead1;
insert new Lead(LastName='testlead1', RAF_Nurture_Campaign__c = 'None',
company='Vtest', Email='[email protected]',Phone = '222222',Status ='Open');
}
@isTest global static void TestRun() {
Test.startTest();
Database.executeBatch(new LeadDuplicateRemove());
Test.stopTest();
}
}