I'm trying to generate a PDF, and in normal Apex execution the function is haulted due to CPU timeout (exceeding 10 second execution time).
So I tried using @future
annotation to use Asynchronous Apex since with Winter '16
we can uyse getContent() and getContentAsPDF() in Asynchronous Apex.
My code looks like this:
public void makePDF() {
MyClass.generatePDF(con.getId(), arecord.Name);
}
@future(callout=true)
public static void generatePDF(Id recId, String recName) {
PageReference pageRef = Page.StmtPDF;
pageRef.getParameters().put('stmtid', recId);
Blob b = pageRef.getContentAsPDF();
Attachment att = new Attachment();
att.Body = b;
att.Name = recName +'.pdf';
att.ContentType = 'application/pdf';
att.ParentId = recId;
insert att;
}
I keep getting same Apex CPU timeout exceeded exception at around 14 second.
May be I'm understanding it incorrectly, but shouldn't I get 60 second timeout in @future method for executing PDF content?
Or my approach is flawed in some way?
== EDIT ==
What does this CRUC update do? - “PageReference getContent() and getContentAsPDF() Methods Behave as Callouts” Critical Update Postponed - Release Notes says that auto-activate
date is postponed and not the update. Am I correct in reading that?