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
etoeto 

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 >
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

 

 

 

 

 

 

samforcesamforce

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

TehNrdTehNrd

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

AutobatAutobat

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!

 

blake.tanonblake.tanon

Has there been a solution to this?

Shaun123Shaun123

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:

VF.html:

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



e.g.
<div class="header">
    <img src="https://c.ap1.content.force.com/servlet/servlet.ImageServer?id=01130000001Qx2q&oid=00D30000000dDJl&lastMod=106607008900" width="720" height="82"/>
</div>

Change to:

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


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

e.g.
<img src="https://c.ap1.content.force.com/servlet/servlet.ImageServer?id=01130000001Qx2q&oid=00D30000000dDJl&lastMod=106607008900" 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 :) ]

CONTROLLER:

(No change here)

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

 

 

Hope that's of use to someone.

 

Cheers,


John