Add dynamic image in Visualforce email templates Lightning Experience

Are you breaking your head of how to insert an image in Visualforce email template in Lightning Experience ? I have a simple 5 steps installation for you.

5 easy steps to make

1. Build your Visualforce email template
2. Upload your logos in Static Resources
3. Create a new field for your logo in Lead object
4. Copy the link of your static resource
5. Insert your link into in Logo field in Lead

Case study: Dynamic logo insertion in Visualforce email templates Lightning Experience.

You have a firm with different departments. They have different logo and addresses but it is a part of the same organisation. You would like to send clients the same email templates but the logo has to change based on different departments.
Company “Alfa” is based in Italy. Logo “Alfa”;
Company “Beta” is based in Germany. Logo “Beta”;
Company “Gamma” is based in Switzerland. Logo “Gamma”;

Condition: Each company has the same type of communication templates.
Goal you want that :
-if we pick up company “Alfa”, in email you see “Alfa” logo;
-if we pick up company “Beta”, in email you see “Beta” logo;
-if we pick up company “Gamma”, in email you see “Gamma” logo;

How to build Visualforce email templates with image insertion in Lightning Experience?

Build your Visualforce email template.

If you need more info of how to create a template of email using visualforce, please, check related article.

There is a part of the code marked as: “Your LOGO”. Here will insert the logo.

2. Upload your logos in Static Resources:

Set Up –> Static Resources — > New.
Don’t forget to make it public:
Cache Control: Public

Add dynamic image in Visualforce email templates Lightning Experience
Add dynamic image in Visualforce email templates Lightning Experience
Add dynamic image in Visualforce email templates Lightning Experience
Add dynamic image in Visualforce email templates Lightning Experience

3. Create a new field for your logo in Lead object:

Set Up –> Object manager –> Lead — > Fields & Relationships –> New . Field type: Picklist
Create a field “Logo”. We will use it for our email templates.

4. Copy the link of your static resource:

Open on uploaded file in static resources –> View file
The file will open in a separate window. Copy link URL.

Add dynamic image in Visualforce email templates Lightning Experience

5. Insert your link into in Logo field in Lead.

Installation is ready. Now your image will be shown in your Visualforce email.

Important nuance for installations!

Your static resources URL on Sanbox and on Organisation environment is different. So, most likely if you test your email templates with the links of logos on Sandbox will work but will not work in Organisation environment. You will have to create directly on Organisation environment (Lightning Experience) :

  • Logo field
  • Static resources with logos
  • Copy the links from ORGANISATION ENVIRONMENT (Lightning Experience) to your logo field

If you want to make it dynamic, send me a request and I will send you an instruction of how to make a dynamic image insertion based on certain conditions.

Leave a Reply

Your email address will not be published. Required fields are marked *