You need to sign in to do that
Don't have an account?
I want to write a program to send documents taking email template into consideration
Here is my program:
public class Outbound_Example_3 {
public void invoke(){
Messaging.SingleEmailMessage msg =new Messaging.SingleEmailMessage();
Contact con=[select id ,AccountId from Contact where createdDate=TODAY];
msg.setTargetObjectId(con.Id);
msg.setWhatId(con.AccountId);
EmailTemplate et =[select id from EmailTemplate where name='Case Response'];
msg.setTemplateId(et.id);
Document doc =[select id,Name,Body,ContentType ,Type from Document where name='Email Messaging'];
Messaging.EmailFileAttachment eft1 =new Messaging.EmailFileAttachment();
eft1.setFileName(doc.Name+doc.type);
eft1.setBody(doc.body);
eft1.setContentType(doc.ContentType);
PageReference p=Page.EmailSerc;
Blob body=p.getContentAsPDF();
Messaging.EmailFileAttachment eft2 =new Messaging.EmailFileAttachment();
eft2.setFileName('EmailSerc');
eft2.setBody(body);
List<Messaging.EmailFileAttachment> files =new List<Messaging.EmailFileAttachment>{eft1,eft2};
msg.setFileAttachments(files);
Messaging.Email[] emails =new Messaging.Email[]{msg};
Messaging.sendEmail(emails);
}
}
Outbound_Example_3 ou=new Outbound_Example_3();
ou.invoke();
Please let me know where am I going wrong.
Thanks!
public class Outbound_Example_3 {
public void invoke(){
Messaging.SingleEmailMessage msg =new Messaging.SingleEmailMessage();
Contact con=[select id ,AccountId from Contact where createdDate=TODAY];
msg.setTargetObjectId(con.Id);
msg.setWhatId(con.AccountId);
EmailTemplate et =[select id from EmailTemplate where name='Case Response'];
msg.setTemplateId(et.id);
Document doc =[select id,Name,Body,ContentType ,Type from Document where name='Email Messaging'];
Messaging.EmailFileAttachment eft1 =new Messaging.EmailFileAttachment();
eft1.setFileName(doc.Name+doc.type);
eft1.setBody(doc.body);
eft1.setContentType(doc.ContentType);
PageReference p=Page.EmailSerc;
Blob body=p.getContentAsPDF();
Messaging.EmailFileAttachment eft2 =new Messaging.EmailFileAttachment();
eft2.setFileName('EmailSerc');
eft2.setBody(body);
List<Messaging.EmailFileAttachment> files =new List<Messaging.EmailFileAttachment>{eft1,eft2};
msg.setFileAttachments(files);
Messaging.Email[] emails =new Messaging.Email[]{msg};
Messaging.sendEmail(emails);
}
}
Outbound_Example_3 ou=new Outbound_Example_3();
ou.invoke();
Please let me know where am I going wrong.
Thanks!
Are you getting error while executing above class??
Thanks & Regards,
Abhishek Singh
Thanks & Regards,
Abhishek Singh.