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:
 
https://AAA.salesforce.com/servlet/servlet. ImageServer?id=BBB&oid=CCC

The link where I found such a possible solution is this:
 
https://salesforce.stackexchange.com/questions/4641/is-is-possible-to-display-an-image-or-icon-in-a-email-using-a-visualforce-templa
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?

Shawn
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:
 
https://help.salesforce.com/articleView?id=Why-images-stored-as-static-resources-cannot-be-seen-in-emails-sent-using-VF-email-templates-1327108316482&language=en_US&r=https%3A%2F%2Fwww.google.es%2F&type=1

 
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(https://help.salesforce.com/articleView?id=000320130&type=1&language=en_US&mode=1)

Solution:
<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.