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

Test class for Batch Apex that deletes records
Hi All,
I am new to Salesforce.
I have written a batch apex to delete records and send a csv file to some email id.
I want to write test class for the same. Here is my code
Please help me
Thanks in Advance
I am new to Salesforce.
I have written a batch apex to delete records and send a csv file to some email id.
I want to write test class for the same. Here is my code
global class Del_leads implements Database.Batchable<sobject> { Public String s; public integer j; Public string k='\n'+'IDName'+','+'CreatedDate'; global Database.QueryLocator start(Database.BatchableContext BC){ return Database.getQueryLocator([SELECT Id,Subject FROM lead]); } global void execute(Database.BatchableContext BC,List<Task> Lds){ s +=k+'\n'+ lds[j].Id+','+lds[j].CreatedDate; Blob b=Blob.valueOf(s); Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment(); efa.setFileName(m+'attachment.csv'); efa.setBody(b); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setToAddresses(new String[] {abc@test.com'}); mail.setSenderDisplayName('Batch Processing'); mail.setSubject('Batch Process Completed'); mail.setPlainTextBody('Please find the attachment of deleted records'); mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); delete Lds; } global void finish(Database.BatchableContext BC){ System.debug(LoggingLevel.WARN,'Deleting Leads Finished'); } }
Please help me
Thanks in Advance
Let us know if this will help you