global class EmailAcknowledgementBatch implements Database.Batchable<sObject>{
public set<ID> emailId = new set<Id>();
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<sObject> scope){
List<Contact> conList = new List<Contact>();
List<Messaging.Email> messages = new List<Messaging.Email>();
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<Contact> 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 });
}
}