Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public PageReference generatePdf() {
- //PageReference pdf = new PageReference('/apex/yourPageName');
- //Page.yourPageName;
- PageReference targetPage = Page.yourPageName;
- targetPage.getParameters().put('id',objOpp.Id);
- //pdf.setRedirect(true);
- system.debug('<<<<<<<pdf : '+targetPage);
- Attachment attach = new Attachment();
- Blob targetBody;
- // try {
- targetBody = targetPage.getContentAsPDF();
- // } catch ( VisualforceException exp ) {
- // targetBody = Blob.valueof('There was an error.');
- // }
- attach.Body = targetBody;
- attach.ContentType = 'application/pdf';
- attach.Name = 'Final quote- '+objOpp.Name +' '+String.valueof(Datetime.now())+'.pdf';
- attach.IsPrivate = false;
- attach.ParentId = objOpp.Id;
- insert attach;
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement