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 Generatepdf_ASE_after_insert on ASE__c (after insert) { List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); for(ASE__c acc : trigger.new) { Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment(); ASE__c accname=[select name from ASE__c where id=:acc.Id]; attach.setContentType('application/pdf'); attach.setFileName('Account Record'); String body; body = '<html><body><h1 style=\"text-align:center;\">Employee Information</h1><br/><br/><table align=\"center\"><tr><td>Employee Name</td><td>' + accname.Name + '</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[] { 'nitin_agrawal@dell.com' }); mail.setSubject('PDF Generation'); mail.setHtmlBody('PFA'); mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach }); mails.add(mail); } if(!mails.isEmpty()) { Messaging.SendEmail(mails); } }
Try this below sample step;
1.Create a Visual Force Email Template Template
Like thw sample below include the field of the record in the message:attachment
<messaging:emailTemplate subject="Account Info" recipientType="User" relatedToType="Account">
<messaging:htmlEmailBody >
Hi
</messaging:htmlEmailBody>
<messaging:attachment renderAs="PDF">
<html>
<head/>
<body>
Hi {!relatedTo.name}
</body>
</html>
</messaging:attachment>
</messaging:emailTemplate>
2.Create a workflow on the object (put the criteria) and add a workflow action Send Email using the above email template
Hope this helps.
All Answers
Are you Creating record on salesforce side or on visualforce page?
Thanks
Nitin
Try this below sample step;
1.Create a Visual Force Email Template Template
Like thw sample below include the field of the record in the message:attachment
<messaging:emailTemplate subject="Account Info" recipientType="User" relatedToType="Account">
<messaging:htmlEmailBody >
Hi
</messaging:htmlEmailBody>
<messaging:attachment renderAs="PDF">
<html>
<head/>
<body>
Hi {!relatedTo.name}
</body>
</html>
</messaging:attachment>
</messaging:emailTemplate>
2.Create a workflow on the object (put the criteria) and add a workflow action Send Email using the above email template
Hope this helps.
you can acheive it by using trigger as well.Here is the code ,its working fine at my org.
Thanks :)