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
Nick Mortensen 2Nick Mortensen 2 

generate quote pdf and email it in apex

I may be missing something very obvious, but I need to figure out how to generate a pdf of an existing quote in Apex.  There has to be some way to call the native PDF generation on the quote page and just pass in the id of the quote as a parameter, but I'm having a hard time finding anything. And then once the quote is generated I would like to be able to email it.  Any help would be greatly appreciated!
Best Answer chosen by Nick Mortensen 2
pbattissonpbattisson
Nick

You will need to use a combination of Visualforce and Apex to manage this. Visualforce pages can be rendered as a PDF using the apex:page attribute
<apex:page renderAs="PDF">

This will render the Visualforce page as a PDF which you can then save. 

This can be simulated in Apex using the getContentAsPDF() method on a PageReference object (which references a particular page). This will return for you a Blob that you can save as a File or Attachment within your org. Apex can also send emails using the Messaging class which you could then use to attach your file to and email out.

All Answers

pbattissonpbattisson
Nick

You will need to use a combination of Visualforce and Apex to manage this. Visualforce pages can be rendered as a PDF using the apex:page attribute
<apex:page renderAs="PDF">

This will render the Visualforce page as a PDF which you can then save. 

This can be simulated in Apex using the getContentAsPDF() method on a PageReference object (which references a particular page). This will return for you a Blob that you can save as a File or Attachment within your org. Apex can also send emails using the Messaging class which you could then use to attach your file to and email out.
This was selected as the best answer
Nick Mortensen 2Nick Mortensen 2
Perfect. Exactly what I was looking for.  Thanks so much!