Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. public static Boolean sendEmail(){
  2.  
  3. // Get template for emails
  4. Id templateId = [SELECT Id
  5. FROM EmailTemplate
  6. WHERE DeveloperName = 'Template'].Id;
  7.  
  8. // Get the related accounts
  9. List<Account> accounts = [SELECT Id, Related_Lead__c FROM Account];
  10.  
  11. List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage> ();
  12.  
  13. // Create the emails
  14. for (Account acc: accounts) {
  15. // Create a new Email
  16. Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
  17.  
  18. // Set the Email template
  19. mail.setTemplateId(templateId);
  20.  
  21. // Set the target account
  22. mail.setWhatId(acc.Id);
  23.  
  24. // Set the recipient
  25. mail.setTargetObjectId(acc.Related_Lead__c);
  26.  
  27. // Create PDF to attach to email
  28. PageReference pdf = Page.AccountPDF;
  29. pdf.getParameters().put('id', acc.Id);
  30. Blob b = pdf.getContent(); // ********* LIMITS ARE HIT HERE **********
  31.  
  32. // Attach the PDF
  33. Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
  34. efa.setFileName('account.pdf');
  35. efa.setBody(b);
  36. mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
  37.  
  38. mails.add(mail);
  39. }
  40.  
  41. // Send the emails
  42. Messaging.sendEmail(mails);
  43. return true;
  44. }
  45.  
  46. Blob b = pdf.getContent(); // ********* LIMITS ARE HIT HERE **********
  47.  
  48. Id templateId = [SELECT Id
  49. FROM EmailTemplate
  50. WHERE DeveloperName = 'Template'].Id;
  51.  
  52. List<Account> accounts = [SELECT Id, Related_Lead__c FROM Account];
  53.  
  54. public static Boolean sendEmail(Account acct, Id templateId ){
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement