Hello everyone, In this post you will find a code block that helps you to save document in Quote PDF object. Generally we all save pdfs or any other documents in file or attachment object but in case of quote there is another related list(Quote PDF) to save pdf on record level. So let's see how we can achieve this by using some apex code.

Save pdf in Quote PDF object

The api name of Quote PDF object is QuoteDocument, so this api name is used in apex code.

Code Sample:

 //VisualforcePageName should be replaced by your org vf page that rendered as PDF
PageReference pref = page.VisualforcePageName;
pref.getParameters().put('Id','XXXXXXQuoteId');//Replace with quote Id
pref.setRedirect(true);
Blob bdata=null;
if(!Test.isRunningTest())
bdata = pref.getContentAsPDF() ;
QuoteDocument quotedoc = new QuoteDocument();
quotedoc.Document = bdata;
quotedoc.QuoteId = 'XXXXXQuoteId'; //Replace with quote Id
insert quotedoc;

Output:

 

Hope you like this post, for any feedback or suggestions please feel free to comment. I would appreciate your feedback and suggestions.
Thank you.