You need to sign in to do that
Don't have an account?
Singamsetti 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();
}
}
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();
}
}
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
Are there workflow rules,triggers or processes on Lead object preventing the insertion?
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.