function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JD2010JD2010 

Calling getContentAsPDF from Trigger

So here's the thing, I realize that salesforce does not support the running of getContentAsPDF from a trigger -- which consiquently, is a royal pain. That said, I decided to embark on a journey to accomplish the task anyway. I've gone a bit into it, and had some success, but wanted to share with some other apex coders that are more versed than I the result, hoping to see if anyone can lend some extra ideas/insight to accomplish this.

 

Thus far, I've been able to actually run the getcontentasPDF as the reslt of a trigger, however, I've been stonewalled in that the returned document is blank (it's a PDF with nothing in it). I've tried it two different ways, and have gotten the same result (blank PDF). So my question is, any ideas on how to make it so the returned PDF is not blank (when you view the VF page normally, it shows properly) or am I stuck?

 

The two ways I am able to run getContentAsPDF:

 

1) When the trigger runs, I have a class that has a function that runs the getContentAsPDF function as a @future method. This works but has the issue of returning a blank pdf.

 

2) Thinking that was their systems way of blocking it, I decided to do a more convoluted and tricky route. The second method is from the trigger I call a visualforce page that has an autorun function that calls getContentAsPDF. This also works successfully, but again, the returned PDF is blank.

 

Any one have any ideas as to why the PDF may be turning up blank?

 

Thanks for any input!

sfdcfoxsfdcfox

What's your use case for this, if I may be so bold to ask? I'm fairly sure that they don't want this to happen because of the associated system load of potentially loading hundreds of PDFs in a single transaction call. I have some ideas, but I don't want to take you down the wrong road, so I'd like some more specifics.

JD2010JD2010

In this case it's to be able to automatically store a proposal. I've built a proposal generator that, based on various fields, creates a PDF document that can be automatically e-mailed. But from a different trigger, I am wanting to be able to generate the PDF of the proposal and automatically create an attachment for it for the Opportunity (I've got everything else running with the exception of a properly rendered/non-blank pdf).

 

That said, I am sure there are other uses I'd have for it in the future. My other question would be, as I can understand them not wanting 1000's of PDFs being created within a few minutes, is there a viable option for if we run into that sort of a situation?

AshanAshan

Hi JD2010,

Have you got any solution for this question. I'm aslo stuck in there. Its seems like there is some authentication issue when we try to call getContent() in a future method.

tsalbtsalb

Almost a year old - and I'm currently looking for a solution to this as well.