0

I have tried to pass the parameter via the vf page from @AuraEnabled method to generate pdf. It does not call the vf page constructor. How can we pass a parameter via the vf page from @AuraEnabled (static)method to normal class?

@AuraEnabled
public static void genearatePDF(List<String> lstOppId) {
    PageReference pdf = Page.GenerateOPPPDF;
    pdf.getParameters().put('wrapperclass', System.JSON.serialize(wcf));
    pdf.setRedirect(true);
    system.debug('!!!pdf'+pdf);
}

Apex class:
public class GenerateOPPPDF {   
public String headings {get;set;}
    public GenerateOPPPDF() {
        List<string> lstId = new List<String>();
        headings =Apexpages.CurrentPage().getParameters().get('wrapperclass');
        system.debug('!!!headings-'+headings);
    }
}
VF Page:
<apex:page controller="GenerateOPPPDF" renderAs="pdf"
     showHeader="false" sidebar="false" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="false">
     Generate PDF-{!headings}
</apex:page>
0

2 Answers 2

1

As written, you're not doing anything with the PageReference here:

PageReference pdf = Page.GenerateOPPPDF;
pdf.getParameters().put('wrapperclass', System.JSON.serialize(wcf));
pdf.setRedirect(true);

You need to call getContentAsPDF() to generate data (a Blob), and then dispose of the data as your application prefers, such as saving a ContentVersion.

Your Visualforce page's controller won't be invoked until the page is actually rendered; right now, you're just holding a reference to the page.

0

You might want to take a "front-door" approach. Instead of trying to call a VF Page from the @AuraEnabled Apex method, open a browser window and open the VF page directly.

You must log in to answer this question.

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