Skip to main content
I have created attachment method in controller for creating attachment record for custom object. However, when i run the page in classic then controller is creating the attachment record and i can able to view the attached file but not from lightning experience window.

 

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;

 

 
2 answers
0/9000