trigger Testobjmail on TestObj__c (After insert) {
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
for(TestObj__c ord : trigger.new)
{
Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
attach.setContentType('application/pdf');
attach.setFileName('Employee.pdf');
String body;
body = '<html><body><h1 style=\"text-align:center;\">Employee Information</h1><br/><br/><table align=\"center\"><tr><td>Employee Name</td><td>' + ord.hello__c + ord.word__c + '</td></tr><tr><td>Age</td><td></td></tr></table></body></html>';
System.debug('HTML is ' + body);
attach.Body = Blob.toPDF(body);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[] { 'xxxx@gmail.com' });
mail.setSubject('PDF Generation');
mail.setHtmlBody('PFA');
mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
mails.add(mail);
}
if(!mails.isEmpty())
{
Messaging.SendEmail(mails);
}
}
Salesforce trigger发PDF 附件
最新推荐文章于 2021-02-22 19:46:06 发布