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

Images in PDF attachment of a Visualforce email Template are missing in time based workflows

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 >

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



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




public static void sendBuggyMails() {
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
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?











I am getting the same problem. Does anybody have any solution to this problem?Is there any work around is possible ?


Has anyone opened a support case? Do this so this issue can be logged.


Im fighting the same problem however i dont get the email coming out, i just get the following error out:



java.lang.NullPointerException: Argument Error: Parameter value is null


This is an interesting problem, its like as soon as either an @future or a timebased workflow runs it cant access parts of the platform.  I have no idea how im going to work around this and the new invoice is required by Monday.  :/  Fun weekend ahead!



Has there been a solution to this?


Hi there,


We've had the same trouble and been working on it with salesforce support for other a month - we found a workaround.  I thought I'd post it just in case anyone's still facing issues on this.


How to render all images for PDFs, when using the automated workflow process:


Replace all <img> and url="" to <apex:image> and url={!Resource.image} tags:

<div class="header">
    <img src="" width="720" height="82"/>

Change to:

<div class="header">
    <apex:image id="image_header" value="{!$Resource.pdf_header_gadwords_2}" width="720" height="82"/>

Replace all url="" to url={!Resource.imageName} tags:

<img src="" width="460" height="454"/>

Change to:
<img src="{!$Resource.header_image}" width="460" height="454"/>

[ Note: Seems to show images when using the <img> tags, but it's best to also change <img> to <apex:image> tags, just in case :) ]


(No change here)

THEREFORE ALWAYS USE <apex:image> and {!Resource.} TAGS !



Hope that's of use to someone.