• Jaromir
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Three days after a particular condition is met, I need to send an email message that includes a PDF attachment. I've set up workflow to do a field update when the time-based condition is met. I have a trigger that detects the field update and generates the email message.

 

To generate the PDF attachment, the trigger has to get a PageReference to the VF page, and then call either getContent() or getContentAsPDF(). Unfortunately, these methods aren't supported in a trigger.

 

[Actually, the documentation says that getContent() isn't supported in a trigger, but it doesn't say the same thing about getContentAsPDF(). It makes sense that, if getContent() isn't supported, neither is getContentAsPDF(), but the documentation should say so. But I digress.]

 

Since the documentation doesn't say anything about getContent() not being supported with @future methods, I wrote an @future method that generates the PDF and sends the email, and changed my trigger to call that. But apparently getContent() doesn't work from an @future method. 

 

[Interestingly, getContent() fails differently when called from a trigger than it does when called from @future. When called from a trigger, getContent() throws an exception. When called from an @future method, getContent() doesn't fail -- it just generates a blank PDF, which is the same the thing doc says it does when called from a unit test. But again, I digress.]

 

Because of the time-based nature of the condition that causes the email to be sent, I need to use workflow to detect the condition. The PDF attachment is complex enough that it needs its own VF controller, so I can't use a messaging:attachment, and I can't use a workflow email action. I need to use a trigger to send the email. Any suggestions on how I can get a trigger to construct and send this email message with its attachment?

 

  • February 05, 2010
  • Like
  • 0