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
Singamsetti Sai TejaSingamsetti Sai Teja 

Batch Apex module challenge unable to cover 100% test coverage?

global class LeadProcessor implements Database.Batchable<sObject> {
    
    global Database.QueryLocator start(Database.BatchableContext bc){
        return Database.getQueryLocator([SELECT LeadSource from Lead]);
    }
    
    global void execute(Database.BatchableContext bc, List<Lead> scope){
        for(Lead Leads : scope){
            Leads.LeadSource = 'Dreamforce';
        }
        update scope;
    }
    
    global void finish(Database.BatchableContext bc){
        
    }
}




@isTest
public class LeadProcessorTest {
    static testMethod void leadProcessorTrailTest(){
        List<Lead> leadList = new List<Lead>();
        for(integer i = 0; i<200; i++){
            Lead leads = new Lead();
            leads.FirstName = 'Ankit';
            leads.LastName = 'Avula'+i;
            leads.Company = 'ARG';
            leadList.add(leads);           
        }
        insert leadList;
        Test.startTest();
        LeadProcessor L = new LeadProcessor();
//l.execute(null,[select leadsource from lead]);
        Database.executeBatch(L);
        Test.stopTest();
    }

}
VinayVinay (Salesforce Developers) 
Hi,

Review below links which can help you.

https://developer.salesforce.com/forums/?id=906F0000000D9AUIA0
https://salesforceuniverse.blogspot.com/2017/01/asynchronous-apex-using-batch-apex.html
http://theblogreaders.com/create-apex-class-uses-batch-apex-update-lead-records-use-batch-apex/
https://salesforce.stackexchange.com/questions/205111/lead-batch-job-trailhead-test-class-not-using-class
https://salesforce-digitalxlien.blogspot.com/2019/09/solving-use-batch-apex-challenge.html

Hope above information was helpful.

Please mark as Best Answer so that it can help others in the future.

Thanks,
Vinay Kumar
David Zhu 🔥David Zhu 🔥
The code is pretty straight forward. I think there could be  issue when runing this line insert leadList;. 
Are there workflow rules,triggers or processes on Lead object preventing the insertion?
Singamsetti Sai TejaSingamsetti Sai Teja
The problem is not with the insertion but failing to 100%test coverage which is required to complete the challenge
Singamsetti Sai TejaSingamsetti Sai Teja

Hi Vinay,

Thanks for the links, But nothing seems to be wrong with my code.

Even tried with the code in those links but not able to cover 100%test coverage.