Issue: If i click the button on custom object record detail page then page successfully creating the notes & attachment record but when i open this file it is showing as "Failed to load PDF document" error.
Can anybody help me to fix this issue.
parentId = Id;(getting the id from soql query)
PageReference pageref= new PageReference('/apex/emp_PDF');
pageref.getParameters().put('Id',empid);
Blob pdfBlob = pageref.getContent();
Attachment myAttach = new Attachment();
myAttach.parentId = parentId;
myAttach.name= 'emp.pdf';
myAttach.body= pdfBlob;
myAttach.ContentType= 'application/pdf';
myAttach.IsPrivate = false;
insert myAttach;