How to Add Images to Salesforce Flow Text Templates for Emails

With Salesforce flow becoming the de facto standard for just about every single thing you build on Salesforce one of the items that often comes up is how do I add an image to a text template that is emailed via flow. You would think that this would be simple and extremely straightforward, but in classic Salesforce style the actual solution is counterintuitive and overall makes no sense.


Let’s Upload the Image

  1. Navigate to Files

  2. Upload the file

  3. Click View File Details

  4. Click Public Link and create a public link with no expiration

  5. Copy the link and navigate to the URL

  6. Right click the image and click copy URL


Configure the Flow

  1. Open the flow that has a text template that needs the image.

  2. Open the Text Template.

  3. Switch the Text Template to View as Plain Text.

  4. Add the URL using a HTML Tag

    • <img src="Image URL" alt="Company Logo">


Let’s Make this Scalable!

So it’s great that we got the image added to the text template, but let’s imagine that based on the running user a different logo should be displayed based on the company recorded on the user’s record. We don’t want to have multiple text templates because that would just become annoying to maintain. So what can we do to solve this? Let’s make this admin serviceable!

  1. Let’s create a Custom Metadata Type called Company Settings.

  2. Create a text field on this metadata type called Logo File Public URL Path.

  3. Create a metadata record for each company and extract the URL path for the file following the above steps.

    • /sfc/dist/version/renditionDownload?rendition=ORIGINAL_Png&versionId=078Ho00000TReJK&operationContext=DELIVERY&contentId=05THo00001mJMdw&page=0&d=/a/Ho000001UYsA/ng3B7iEk27MWksfm7qOUBDP4PUOT1vz7GoBeebxURM0&oid=00DHo0000017Xbl&dpt=null&viewId=

Now that we have our metadata built let’s open the flow and get to work on making this dynamic.

1. Get the Company Setting metadata relevant to the running user.

  • As a best practice, we always create a default metadata record just in case the user is not configured properly and no setting record is found.

2. Create a formula field to dynamically construct the image URL. This formula will construct the appropriate salesforce URL that corresponds to the environment you are in.

  • LEFT({!$Api.Partner_Server_URL_340},FIND("/services", {!$Api.Partner_Server_URL_340})) & {!CompanySetting.LogoDocumentUrlPath__c}

3. Now let’s go back to our text template and update the image reference in our HTML tag to our formula.

And bam. Now you have built a configurable solution so that as company images change or new companies are added you can simply add a metadata record and never have to touch this automation again!

Previous
Previous

Custom Salesforce Forecasting for Accounts, Opportunities, or Any Object!

Next
Next

Block Deletion of Email Messages, Events, and Tasks