+ Start a Discussion
Rupesh YangalreddyRupesh Yangalreddy 

I have an requirement .. i have pdf that shows the data of the quote but now insted of showing data into pdf , i need to attach the pdf to quote .. I dnt have any idea how to do it ..Any thoughts ?

Best Answer chosen by Rupesh Yangalreddy
Raj VakatiRaj Vakati
You need to use the QuoteDocument Sobject .. 



sample code is here 
 
QuoteDocument attachment = new QuoteDocument();
        attachment.QuoteId = recordId; 
        PageReference pdf = Page.YOURPAGENAME;
        pdf.getParameters().put('Id', recordId);
        pdf.getParameters().put('displayOnly', '1');
        pdf.setRedirect(true);
        try {
            attachment.document = !Test.isRunningTest() ? pdf.getContent() : Blob.ValueOf('dummy text');
        }
        catch (Exception e) {
            attachment.document  = Blob.valueof('There was an error.');
            String msg='Unexpected Error. Error Message - '+e.getMessage();
        }
        
        insert attachment;

 

All Answers

Raj VakatiRaj Vakati
You need to use the QuoteDocument Sobject .. 



sample code is here 
 
QuoteDocument attachment = new QuoteDocument();
        attachment.QuoteId = recordId; 
        PageReference pdf = Page.YOURPAGENAME;
        pdf.getParameters().put('Id', recordId);
        pdf.getParameters().put('displayOnly', '1');
        pdf.setRedirect(true);
        try {
            attachment.document = !Test.isRunningTest() ? pdf.getContent() : Blob.ValueOf('dummy text');
        }
        catch (Exception e) {
            attachment.document  = Blob.valueof('There was an error.');
            String msg='Unexpected Error. Error Message - '+e.getMessage();
        }
        
        insert attachment;

 
This was selected as the best answer
Rupesh YangalreddyRupesh Yangalreddy
Thank you.