global class EmailAcknowledgementBatch implements Database.Batchable{ public set emailId = new set(); global Database.querylocator start(Database.BatchableContext BC){ return Database.getQueryLocator([select id,Name,Email,Date__c,CreatedDate from Contact where CreatedDate >=:system.today()]);} global void execute(Database.BatchableContext BC, List scope){ List conList = new List(); List messages = new List(); for(sObject s : scope){ Contact a = (Contact)s; if(a.Email != Null){ // email = a.Email; emailId.add(a.Id); Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); message.setTargetObjectId(a.Id ); //message.setWhatId( a.Id ); message.setSenderDisplayName('Batch Example'); // message.setPlainTextBody('Batch Process has completed'); message.setSubject('Acknowledgement !!!'); // // message.setPlainTextBody('Dear ' + a.Name + 'Your Profile is created with'+a.Email +'Email'); messages.add( message ); } } // Send all the e-mails. Messaging.SendEmailResult[] results = Messaging.sendEmail( messages ); //update conList; } global void finish(Database.BatchableContext BC){ //List con = [select id,Email,Date__c,CreatedDate,Name from Contact where CreatedDate <=:system.today() ]; //Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage(); //mail.setTargetObjectIds(emailId); //system.debug('----email--->>>' + email); //mail.setSenderDisplayName('Batch Example'); // mail.setPlainTextBody('Batch Process has completed'); //mail.setSubject('Acknowledgement !!!'); // //subject //mail.setPlainTextBody('Dear ' + con[0].Name + 'Your Profile is created with'+con[0].Email +'Email Id'); //Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail }); } }