You need to sign in to do that
Don't have an account?
fiona gentry
Please help me in writng a test class for scheduled batch apex below ,i want 100% code coverage please
Thanks,
Fiona
Need a Test class for Scheduled Batch apex
Hi Gurus,
Please help me in writng a test class for scheduled batch apex below ,i want 100% code coverage please
global class ERTExtract255BatchClass implements Database.Batchable<sObject>, Database.Stateful { global Database.QueryLocator start(Database.BatchableContext bc) { return Database.getQueryLocator( 'SELECT ID,Description,Case_Desc_255__c FROM Case' ); } global void execute(Database.BatchableContext bc, List<Case> scope){ // process each batch of record List<Case> lstCase = new List<Case>(); for (Case cas : scope) { cas.Case_Desc_255__c = cas.Description.Left(255); lstCase.add(cas); } update lstCase; } global void finish(Database.BatchableContext bc){ Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); AsyncApexJob a = [Select a.TotalJobItems, a.Status, a.NumberOfErrors, a.JobType, a.JobItemsProcessed, a.ExtendedStatus, a.CreatedById, a.CompletedDate From AsyncApexJob a WHERE id = :BC.getJobId()]; // below code will send an email to User about the status String[] email = new String[]{'.com'}; mail.setToAddresses(email); mail.setReplyTo('abc@gmail.com'); mail.setSenderDisplayName('ERT Extract First 255 Char Batch Processing'); mail.setSubject('Batch Processing '+a.Status); mail.setPlainTextBody('The Batch Apex job processed '+ a.TotalJobItems+'batches with '+a.NumberOfErrors+'failures '+'Job Item processed are '+a.JobItemsProcessed); Messaging.sendEmail(new Messaging.Singleemailmessage [] {mail}); } }
Thanks,
Fiona
David Zhu 🔥
You may refer to the code below:
fiona gentry
Hi David thanks ,but i am getting below exception when I ran the above test
fiona gentry
here is the updated batch apex class