You need to sign in to do that
Don't have an account?
Marco Zeuli
Queueable interface and getContentAsPDF
Hi all,
today i'm facing some issues with the queueable interface.
This is my use case:
i gave to send an email with a pdf attachment when an object is created.
This is my solution:
When user create a record, a queueable class is instantiated and enqueued in the apex job queue. The queueable class receive the Account as input and than create the PDF and send it by email.
This is my problem:
the generated job stuck in the queue for hours until a System Error is returned.
This is my code:
page to render as pdf
this is the page controller
It has also a static method to enqueue the job.
this is the queueable class
In my ORD i enabled the critical update from SUmmer 15, so the getContentAsPDF behave as a callout.
Could you help me with this?
today i'm facing some issues with the queueable interface.
This is my use case:
i gave to send an email with a pdf attachment when an object is created.
This is my solution:
When user create a record, a queueable class is instantiated and enqueued in the apex job queue. The queueable class receive the Account as input and than create the PDF and send it by email.
This is my problem:
the generated job stuck in the queue for hours until a System Error is returned.
This is my code:
page to render as pdf
<apex:page showHeader="true" sidebar="true" controller="TestQueueAndPDFCtrl" renderAs="{!renderAs}"> <apex:outputText value="test content {!accid}" /> </apex:page>
this is the page controller
public with sharing class TestQueueAndPDFCtrl { public String accid {get;set;} public String renderAs {get;set;} public TestQueueAndPDFCtrl() { // get account id from parameter and set on the page accid = ApexPages.currentPage().getParameters().get('accId'); renderAs = ApexPages.currentPage().getParameters().get('renderAs'); } public static void sendPdf() { /* create an account and then send the id by email */ Account a = new Account(); a.Name = 'marco'; insert a; Id job = System.enqueueJob(new TestQueueableWithCallout(a)); } }
It has also a static method to enqueue the job.
this is the queueable class
public class TestQueueableWithCallout implements Queueable, Database.AllowsCallouts { private Account a; public TestQueueableWithCallout(Account a) { this.a = a; } public void execute(QueueableContext context) { System.debug('queueble started!!!'); PageReference pdf = Page.TestQueueAndPDF; pdf.getParameters().put('accId', a.id); pdf.getParameters().put('renderAs', 'PDF'); Blob b = pdf.getContentAsPDF(); // Blob b = Blob.valueOf('ciao'); Messaging.EmailFileAttachment att = new Messaging.EmailFileAttachment(); att.setFileName('ciao.pdf'); att.setbody(b); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setToAddresses(new List<String>{'m.****@****.it'}); mail.setsubject('test'); mail.setFileAttachments(new List<Messaging.EmailFileAttachment>{att}); mail.sethtmlbody('body'); Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail}); System.debug('done'); } }
In my ORD i enabled the critical update from SUmmer 15, so the getContentAsPDF behave as a callout.
Could you help me with this?
What is the error? Can you please provide the whole error message?
Thanks and Regards,
Anirudh Singh
this is the error i get in the Apex Job queue
Salesforce System Error: 1248989408-9559 (115151481) (115151481)
If i run this from anonymous console
I get these debug logs:
anonymous:
queueable
It's seems that the queueable class stops at the getcontentaspdf ....