I have an image stored as a document. I put this image in an email template and reference it by doing:

<img id="toplogo" src="{!LEFT($Api.Partner_Server_URL_140, FIND('.com/',$Api.Partner_Server_URL_140)+3)}/servlet/servlet.ImageServer?id=015G0000001f7xo&oid={!$Organization.Id}" height="20"/>

All good. Problem is when I build a package and installed this image in another org, it will get another Id. I need to be able to do something like this:

Document document = [Select Id, Url From Document Where DeveloperName = 'MyImage'];
// can now use document.URL

Is it possible to execute that code in a VF Email template?


2 Answers 2


VF email template can't have a controller / controller extension. You can however embed a component (<c:myCustomComponentTag imageName="MyLogo"/> or something like that) and this thing could have a controller.

Alternatively inform the package installators that they'll get new Id, the can't edit your email template but they can clone it and put links to logos of their choice?

Or store the link to logo in a custom setting and again - let the client admins edit the values?

  • this is a good lead thanks. I have a few other questions but it makes sense to put them in a separate thread.
    – dublintech
    Commented Jan 18, 2013 at 12:11

I guess salesforce supports controller in visualforce templates. You can do the query in the controller and use the merge field to populate the image Id.

Additionally you can think of putting the image in a static resource and use {$Resource.} to import the image

  • 1
    static resources are not considered a good idea for email templates.
    – dublintech
    Commented Jan 17, 2013 at 11:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .