Good day Everyone. I am trying to create a functionality that will create a pdf and make it as an attachment. It is working fine when you are an authenticated user however when I try to create a public site and from their call the class that will create a pdf, the pdf is created but when you try to open it, an error will show saying "Failed to load PDF document.". What are the possible reason of this error ? Please help. thank you. Below is my sample code.


global class AS_pdfTriggerController{
 @Future(callout=true) @auraEnabled
    webservice static void addinvoicePDFandEmail(list<id> IdList){
        Account acc = new Account();
        acc.Name = 'testing for PDF';
        acc.RecordTypeId = '0125D000000Ck2C';
        Insert acc;

         //create a pageReference instance of the VF page.
        pageReference pdf = Page.testPdf;
        //pass the Account Id parameter to the class.
    //    pdf.getParameters().put('id',orderId);
        Attachment attach = new Attachment();
        Blob body;
            body = pdf.getContent();
        attach.Body = body;
        attach.Name = 'testPDF.pdf';
        attach.IsPrivate = false;
        attach.ParentId = acc.Id;
        insert attach;

testPdf PAGE:

<apex:page showHeader="false" renderAs="pdf">

1 Answer 1


There might be chances that you are missing the required permission of Account object for this guest user.

So first check your guest user have all required permission.

Then you need to make sure The Guest User is able to directly access the visualforce page which you render as PDF. So in order to provide access to it you have to construct a URL for it. If the Guest User finds the path through its URL it will support the call getContentAsPDF(); and values will be present in the PDF.

  • 1
    Thank you so much mate. I already check the permission and it is fine. I also already added the visualforce page. What I am missing is that I use the url for authenticated user and not for guest I just realized it after viewing your comment.
    – Hope
    Commented Mar 1, 2018 at 3:10
  • @Hope How did you use the unauthenticated url?
    – simplikios
    Commented Nov 9, 2022 at 16:05
  • Figured it out. PageReference pageRef = new PageReference('https://somecustomsite.com/vf');
    – simplikios
    Commented Nov 9, 2022 at 16:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .