Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Boolean sendEmail(){
- // Get template for emails
- Id templateId = [SELECT Id
- FROM EmailTemplate
- WHERE DeveloperName = 'Template'].Id;
- // Get the related accounts
- List<Account> accounts = [SELECT Id, Related_Lead__c FROM Account];
- List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage> ();
- // Create the emails
- for (Account acc: accounts) {
- // Create a new Email
- Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
- // Set the Email template
- mail.setTemplateId(templateId);
- // Set the target account
- mail.setWhatId(acc.Id);
- // Set the recipient
- mail.setTargetObjectId(acc.Related_Lead__c);
- // Create PDF to attach to email
- PageReference pdf = Page.AccountPDF;
- pdf.getParameters().put('id', acc.Id);
- Blob b = pdf.getContent(); // ********* LIMITS ARE HIT HERE **********
- // Attach the PDF
- Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
- efa.setFileName('account.pdf');
- efa.setBody(b);
- mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
- mails.add(mail);
- }
- // Send the emails
- Messaging.sendEmail(mails);
- return true;
- }
- Blob b = pdf.getContent(); // ********* LIMITS ARE HIT HERE **********
- Id templateId = [SELECT Id
- FROM EmailTemplate
- WHERE DeveloperName = 'Template'].Id;
- List<Account> accounts = [SELECT Id, Related_Lead__c FROM Account];
- public static Boolean sendEmail(Account acct, Id templateId ){
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement