• samforce
  • NEWBIE
  • 0 Points
  • Member since 2010

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

Images in PDF attachment of a Visualforce email Template are missing in time based workflows or when called from @future method:

 

I have a VF email template which references images from a static resource. This works perfectly, if I send the email from workflow rule, except for, if it is a time based workflow or if the workflow is a result of a change made in a @future apex method.

 

The email is still sent out, but all images are missing and are replaced by the standard VF-icon for missing images.

 

Easy Steps to reproduce:

 

1. create a simple VF email with PDF attachment

 

 

<messaging:emailTemplate subject="BugTest" recipientType="Contact">
<messaging:htmlEmailBody >
Body
</messaging:htmlEmailBody>

<messaging:attachment renderAs="pdf" filename="bugTest.pdf">
<img src="{!URLFOR($Resource.pdfLogo)}"/>
</messaging:attachment>

</messaging:emailTemplate>

 

2. create a method which uses the template (replace the IDs with IDs from your org)

 

 

@Future

public static void sendBuggyMails() {
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setTargetObjectId('003S0000004qO5I');
email.setTemplateId('00XS0000000QN6W');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
}

 

3. Call the @future.method e.g. from execute anonymous

 

==> you receive an email with a PDF attachment but without the image

 

4. Remove the @future annotation and call the method again

 

==>  you receive an email with a PDF attachment including the image

 

 

The same issue happens, when the email is sent from a time based workflow, or from a workflow which was triggered from a @future-method.

 

 

Is this a bug or am I doing something wrong here?

 

 

Ingo

 

 

 

 

 

 

  • November 03, 2009
  • Like
  • 0