• Sean Churchill 9
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi all,

can anyone help with a example of test code so i can test the following batch code please?
 
global class BulkRecordDelete implements Database.Batchable<sObject> {

    
    global string obj;
    private string query = 'SELECT Id FROM ';

    global database.querylocator start(Database.BatchableContext BC) {
        query = query + obj;
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<sObject> scope) {
        List<sObject> ob = new List<sObject>();

        for(sObject s : scope) {
            ob.add(s);
        }
        delete ob;
    }
    
    global void finish(Database.BatchableContext BC) {
        
		if (ApplicationClass.BatchEmailsEnabled) {
	        Id userId = UserInfo.getUserId();
	        String notify = [select Email from User where Id = :userId].Email;
	        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
	
	        mail.setToAddresses(new String[] {notify});
	        mail.setReplyTo('batch@acme.com');
	        mail.setSenderDisplayName('Batch Processing');
	        mail.setSubject('Batch Process Completed');
	        mail.setPlainTextBody('Bulk ' + obj + ' delete has completed');
	
	        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
		}
    }
}
Thanks...