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
Rocio VivancoRocio Vivanco 

How to add an image to a Visualforce email template without using hard coding?

Hi all,

I have been looking for an answer to my question: how to add an image to a Visualforce email template without using hard coding?.
Some say a possibility to add an image is storing the image in the Documents tab and then use this URL for the image: ImageServer?id=BBB&oid=CCC

The link where I found such a possible solution is this:
The problem is: what about if you have many email templates to deploy in another organization?. Hence, hardcoding within the Visualforce email template in order to show the image, for example, the logo of an organization, is not a good solution.

We have 100 Visualforce email templates using the suggested URL, ok, it works, the image is being shown when you send the email, but as said, the problem is in the deployment of these email templates because of the use of hardcoding.

I would appreciate messages here how you solved this otherwise? (I have read that use of static ressources for this is not recommendable as well).

Shawn Reichner 29Shawn Reichner 29
You could use a static resource and call this on your VF Page.  When you then move this to other orgs, in your change set you just include the static resource. 

Does this help?

Rocio VivancoRocio Vivanco
Thanks Shawn for your answer, but I have read that when you use a static resource and you sent the email, the image can not be displayed. Salesforce says:

Harshit SethiHarshit Sethi
We ran into a similar problem and after trying various solutions, the following worked for us.

In our case, the image was uploaded as a content asset(

<img src="{!LEFT($Api.Partner_Server_URL_260,FIND('/services',$Api.Partner_Server_URL_260))}/file-asset-public/<Image_Name_Here>?oid={!$Organization.Id}&height=50&width=50"/>
Hope this helps.