I have a future annotated method which should generate a pdf in PdfController, the method is as below:

public static void savePdfAsAttachment(Id applicationId){
    PageReference p = Page.PdfGeneratorPage;
    p.getParameters().put('applicationId', applicationId);
    Blob pdfBlob;
    if(Test.isRunningTest()) { 
        pdfBlob = blob.valueOf('Unit.Test');
    } else {
        pdfBlob = p.getContent();
    Application__c applicationRecord = [Select id, Name from Application__c where id = :applicationId];
    Attachment attachmentPDF = new Attachment();
    attachmentPDF.parentId = applicationId;
    attachmentPDF.Name = applicationRecord.Name;
    attachmentPDF.contentType = 'application/pdf';
    attachmentPDF.Description = '';
    attachmentPDF.Body = pdfBlob;
    List<Attachment> attachments = [select id from Attachment where parentId =:applicationId and name =: attachmentPDF.Name];
        attachmentPDF.Id = attachments[0].Id;
    upsert attachmentPDF;

when this method is called from a method from AppController (most of main business logic is inside this one), like below:

public static void updateApplication(Id applicationRecordId) {
    ...... // code for other business logic is here
    update objApp;

I am getting below error once it executes PdfController.savePdfAsAttachment method

You do not have sufficient privileges to access the page: /apex/pdfgeneratorpage

enter image description here

Can anybody help me resolve this issue please.

  • 1
    Does the running user's profile have access to the page? Aug 10, 2021 at 15:24

1 Answer 1


You are on the right path, grant the permission on either the Profile or Permission Set for the user to page 'pdfgeneratorpage' as Aditya mentioned.

You must log in to answer this question.

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