You need to sign in to do that
Don't have an account?

Generate PDF with apex trigger
I am currently trying to have a PDF created based on a field update.
The issue is that it seems that getContent() and getContentAsPDF() don't work when called within a trigger.
Does anyone know a work around for this or is this something that I won't be able to accomplish.\
Thanks
Have you tried seperating this logic into a class with @future, and then calling it to do your logic asynchronously?
It now allows me to do it except the only problem is that the PDF is now coming out blank.
above is the code for my class and trigger
You probably need to pass in the ID otherwise the page doesn't know what it's rendering....
try the following if your page has a standardController for Account:
@future (callout=true) public static void createPDF(ID Id) { PageReference pdf = Page.AccountsPDF; pdf.getParameters().put('id', String.valueOf(Id)); Attachment attach = new Attachment(); attach.ParentId = Id; attach.name = 'name.pdf'; attach.body = pdf.getContentAsPDF(); insert attach; }
I tried the fix above but unfortunately it is still returning a blank pdf.
Looking back at old code, when I had to do something similar... only difference I can really tell is the SetRedirect Option... This was the code I used....
Visualforce Page
Component was just used mostly to style the page
Hello,
The issue is that you are not able to use getContent() or getContentAsPDF() methods in:
Please see another way http://corycowgill.blogspot.ch/2012/02/generating-pdf-in-apex-trigger.html
Hope it helps.
Does this include asynchronous calls though? I thought this was possible through the use of method with @future annotation.
Hi Alex,
Unfortunately the getContent and getContentAsPDFPageReference methods cannot be used in methods with the future annotation.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm
Thanks
even though no fields are changing on the record.