BatchClassforContact


SUBMITTED BY: Guest

DATE: Jan. 22, 2014, 12:07 p.m.

FORMAT: Text only

SIZE: 2.2 kB

HITS: 4624

  1. global class EmailAcknowledgementBatch implements Database.Batchable<sObject>{
  2. public set<ID> emailId = new set<Id>();
  3. global Database.querylocator start(Database.BatchableContext BC){
  4. return Database.getQueryLocator([select id,Name,Email,Date__c,CreatedDate from Contact where CreatedDate >=:system.today()]);}
  5. global void execute(Database.BatchableContext BC, List<sObject> scope){
  6. List<Contact> conList = new List<Contact>();
  7. List<Messaging.Email> messages = new List<Messaging.Email>();
  8. for(sObject s : scope){
  9. Contact a = (Contact)s;
  10. if(a.Email != Null){
  11. // email = a.Email;
  12. emailId.add(a.Id);
  13. Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
  14. message.setTargetObjectId(a.Id );
  15. //message.setWhatId( a.Id );
  16. message.setSenderDisplayName('Batch Example');
  17. // message.setPlainTextBody('Batch Process has completed');
  18. message.setSubject('Acknowledgement !!!'); // //
  19. message.setPlainTextBody('Dear ' + a.Name + 'Your Profile is created with'+a.Email +'Email');
  20. messages.add( message );
  21. }
  22. }
  23. // Send all the e-mails.
  24. Messaging.SendEmailResult[] results = Messaging.sendEmail( messages );
  25. //update conList;
  26. }
  27. global void finish(Database.BatchableContext BC){
  28. //List<Contact> con = [select id,Email,Date__c,CreatedDate,Name from Contact where CreatedDate <=:system.today() ];
  29. //Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
  30. //mail.setTargetObjectIds(emailId);
  31. //system.debug('----email--->>>' + email);
  32. //mail.setSenderDisplayName('Batch Example');
  33. // mail.setPlainTextBody('Batch Process has completed');
  34. //mail.setSubject('Acknowledgement !!!'); // //subject
  35. //mail.setPlainTextBody('Dear ' + con[0].Name + 'Your Profile is created with'+con[0].Email +'Email Id');
  36. //Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });
  37. }
  38. }

comments powered by Disqus