+ Start a Discussion
Mhlangano KhumaloMhlangano Khumalo 

Site page saves blank pdf attachment

I’ve created a class to create a pdf attachment upon inserting of a lead record with fields mapped from the lead.
 
The web to lead form works fine when the form is filled within VF pages. The only problem is it saves a blank pdf page when done through the site page. If enabled Read & Edit permissions on the Lead plus Field Level security on every field but still doesn’t populate the pdf.

What could be the problem? Below is the code
public with sharing class CreatePdfOnLead{
    @Future(callout=true)
    public static void savePdf(Id leadId){

    PageReference pagePdf = new PageReference('/apex/ApplicationPDFonLead?id='+leadId); 
    blob body = pdf.getContentAsPDF();
    string filename = 'File Name';
        
    attachment theFile = new attachment();
    theFile.isPrivate = false;
    theFile.body = body;
    theFile.ParentId = leadId;
    theFile.Name = filename;
    insert theFile;        
    }         
}
Trigger that creates the attachment
trigger MergonCreatePdfOnLeadTrg on Lead (after insert) {
    for(Lead thelead :Trigger.New){        
        //Invoke the method
        CreatePdfOnLead.savePdf(thelead.Id);
        }
}
I strongly suspect it has to do with permissions on the site page because if the record owner/creator is sys admin the pdf is populated.  If the owner is site quest user, it shows a blank page. It does not even show static text on the page that's not mapped to fields, Any Ideas?

 
bob_buzzardbob_buzzard
Have you given access to the CreatePdfOnLead page to the guest user profile? What happens if you try to open that page directly from the site?