function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Aravind RAravind R 

I want to generate the pdf of the record after save.

Once the user saves the record, it must be saved as pdf and it should be mailed as an attachment to the record owner.
Best Answer chosen by Aravind R
gokul bharatigokul bharati
Hi Arvind,

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

Sfdc CloudSfdc Cloud
Hi Arvind,
 Are you Creating record on salesforce side or on visualforce page?

Thanks
Nitin
Aravind RAravind R
I am creating on salesforce side
gokul bharatigokul bharati
Hi Arvind,

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.
This was selected as the best answer
Sfdc CloudSfdc Cloud
Hi Arvind
you can acheive it by using trigger as well.Here is the code ,its working fine at my org.
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);
}
}

Thanks :)