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

Need Help writting a 100% code coverage test class for Batch
Hi there,
I'm quite stuck here.
I've written a test class for my batch but it doesn't appears to be running. It stays at 0% :(
I'm missing something but don't know what.
Can someone help me figure it out?
Here is my batch class :
And this is my attemp of writting a proper test class :(
Ty very much for your help
I'm quite stuck here.
I've written a test class for my batch but it doesn't appears to be running. It stays at 0% :(
I'm missing something but don't know what.
Can someone help me figure it out?
Here is my batch class :
global class BatchUpdateAllLeads implements Database.Batchable <SObject> { //START METHOD global Database.QueryLocator start(Database.BatchableContext bc){ String Query='Select id,TECH_Update__c from Lead where TECH_Update__c=false AND Converted=false ' ; return Database.getQueryLocator(Query); } //EXECUTE METHOD global void execute(Database.BatchableContext bc, List<Lead> scope){ for(Lead l: scope){ l.TECH_Update__c = true; } update scope; } //FINISH METHOD global void finish(Database.BatchableContext bc){ Id job= bc.getJobId(); System.debug(job); } }
And this is my attemp of writting a proper test class :(
@istest private class BatchUpdateAllLeads_TEST { @istest static void testAcc(){ List<Lead> l = new List<Lead>(); Lead l1 = new Lead(Company ='BTP',LastName = 'Test',SIRET__c='12659991955626',Numero_d_ordre__c='9999-99-99',Region_GRDF__c='Ile de France',Tech_Update__c=false,IsConverted=false); l.add(l1); Lead l2= new Lead(Company ='Comp',LastName = 'Test2',SIRET__c='12659991955687',Numero_d_ordre__c='1111-99-99',Region_GRDF__c='Ile de France',Tech_Update__c=false, IsConverted=true); l.add(l2); Lead l3= new Lead(Company ='Agny', LastName = 'Test3', SIRET__c='19959991988687', Numero_d_ordre__c='1111-99-11', Region_GRDF__c='Ile de France', Tech_Update__c=true,IsConverted=true); l.add(l3); insert l; Test.startTest(); BatchUpdateAllLeads ap= new BatchUpdateAllLeads(); Id jobid= Database.executeBatch(ap); Test.stopTest(); } }
Ty very much for your help
Please update your both class Apex Class as well as test class by the following code to achieve 100% Code Coverage.
Apex Class.
Test Class.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Sachin Arora
www.sachinsf.com
All Answers
Please try chaging you batch class query on line 4. You field for converted should be isConverted like below:
And try with below test class:
Hope this helps!
Thanks
Please update your both class Apex Class as well as test class by the following code to achieve 100% Code Coverage.
Apex Class.
Test Class.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Sachin Arora
www.sachinsf.com
You helped me a lot to correct my careless mistakes. Really when i posted it, seemed all fine.
Ty very much for this second look and your precious time.
Now i Hit my 100% code coverage !
Attitude Status: https://www.hindiattitudestatus.in/2020/03/attitude-status-in-hindi-for-whatsapp.html
Website: https://www.hindiattitudestatus.in
Top 2 Website for Sarkari Bank Jobs (https://www.sarkaribankjobs.com)
Ipbs po, Sbi Jobs, IBPS PO, IBPS Clerk, SBI Clerk visit: https://www.sarkaribankjobs.com
http://salesforcecodes.com/test-class-for-batch-apex/