Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question
up vote 3 down vote accepted

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?

share|improve this answer
this is a good lead thanks. I have a few other questions but it makes sense to put them in a separate thread. – dublintech Jan 18 '13 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

share|improve this answer
static resources are not considered a good idea for email templates. – dublintech Jan 17 '13 at 11:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.