Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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?

Thanks

share|improve this question
add comment

2 Answers 2

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

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
1  
static resources are not considered a good idea for email templates. –  dublintech Jan 17 '13 at 11:11
add comment

Your Answer

 
discard

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.