function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
trigger sendEmailToContact on Contact (after insert, after update) { List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); for(Contact c : trigger.new) { Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment(); attach.setContentType('application/pdf'); attach.setFileName('Contact.pdf'); String body; body = '<html><h1 style=\"text-align:center;\">Contact Information</h1><br/><br/><table align=\"center\"><tr><td>Contact Name</td><td>' + c.Name + '</td></tr><tr><td>MobilePhone</td><td>' + c.MobilePhone + '</td></tr><tr><td>Email</td><td>' + c.Email + '</td></tr></table></html>'; System.debug('HTML is ' + body); attach.Body = Blob.toPDF(body); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setToAddresses(new String[] { c.Email }); mail.setSubject('PDF Generation'); mail.setHtmlBody('PFA'); mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach }); mails.add(mail); } if(!mails.isEmpty()) { Messaging.SendEmail(mails); } }
Trigger:
Create contact with Name,Phone and Email fields.Once you Created contact you will receive one email with PDF attachement .
Output:
[If it helps, mark it as "Best Answer"]
Thanks,
Rockzz