I am working on converting some JS buttons to Lightning. These buttons invoke an Apex class that calls getContent() on a VisualForce page with a renderas attribute of PDF & then store that output in a QuoteDocument record. This logic works fine when I invoke it from a JS button. But when I try to invoke the same Apex class from a LWC Quick Action, the call to getContent() returns an HTML file w/a JS redirect to the VisualForce page.
I understand that getContent() is not allowed in Email Services & Triggers & Test classes. But is it also not allowed in LWC Quick Actions?
GetContent() seems to be behaving as if I'm not logged in. Is there something I need to do for getContent() to run as if I'm logged in?
Do I need to replace my call to getContent with an HTTP request to the VisualForce page (which would require setting up a Named Credential for it)?
Here is the Apex class in question:
global class QuoteDocumentFactory_EU {
@AuraEnabled
Webservice static string createPdf(string quoteId) {
Quote quote = [select CurrencyIsoCode, Discount, GrandTotal from Quote where Id = :quoteId];
PageReference pdf = new PageReference('/apex/QuotePDF_EU?id=' + quoteId);
Blob content = (!Test.isRunningTest()) ? pdf.getContent() : blob.valueof('TEST');
QuoteDocument document = new QuoteDocument(
QuoteId = quoteId,
Document = content
);
insert document;
return document.Id;
}
}