Being able to insert a salesforce image using a formula is very easy to implement, and can act as a visual cue for a variety of use cases. Recently, I had a request to flag accounts with bad payment statuses on a custom object record used by the implementation team, because at a certain point the customer’s access would be restricted causing the engineer to be unable to have meetings with the end users. Other reasons for using visual representations can be showing where an opportunity stands (red, yellow, green) when closing, using a lead score to see how hot the lead is (with flame images), or using an account score and how close a prospect is to your ideal customer profile (with stars), etc. Adding a field to Salesforce that will display as an image requires a few steps, but we’ll walk through it with screenshots below.
How to Insert an Image in Salesforce
To insert an image in Salesforce, we’ll first have to upload the image into Salesforce. The recommended way is to upload the image in the Documents Tab. To head to the documents tab, click the plus sign in the menu to view all tabs. Then select the Documents tab.
The second step is to create a read only public folder visible to all users, or take an existing folder and set the access to ‘read only’ accessible by all users. I’ve named mine SFDC Images below:
Now that we have the folder set up, we’ll need to actually upload the pictures. I searched Google for a white flag Icon that was free (creative commons), and downloaded it to my computer. From there, I painted in some colors (green, yellow, red, black), and shrunk the size down a bit. Here they are if you’d like to use them in your own Org:
Next, you’ll want to create a new document, and give it a name. Make sure you have it saved in the public “SFDC Images” folder. From there, upload the image by selecting ‘browse’ in the second section. Do this for all the images you want to upload.
Now, you want to click ‘view file’ to get the url. We’ll save everything after http://[…].content.force.com (what you will be copying is the ‘/servlet/servlet.FileDownload?file=01541000003RMXC‘).
Once we have the location URLs saved for all images, we can create the field that will display them. Select the create new Field on the Object you want to display the images. For this example, we’ll create one on the Lead Object.
Select type “Text” for the data the formula will return, and give it a name:
In the formula builder – we’ll want to go to “Advanced Formula” tab. The formula I’m making will be using the CASE logic.
What this formula does is lookup the Lead’s Score, and if the picklist value is ‘Medium’ , it will display the Yellow Flag. If the Lead Score = “High”, it will display the Green Flag. All other times it will display the Red Flag. The Image function has two variables, the URL of the image, and the name of the image. Here is the formula below if you’d like to copy and paste to update yourself.
CASE( Lead_Score__c,
“Medium”, IMAGE(“/servlet/servlet.FileDownload?file=01541000003RMXM”, “Yellow”),
“High”, IMAGE(“/servlet/servlet.FileDownload?file=01541000003RMXC”, “Green”),
IMAGE(“/servlet/servlet.FileDownload?file=01541000003RMXH”, “Red”)
)
Save the formula, and add it to your page layout on the record type you want to display it on. Once you have updated the layout, let’s validate this by going to one of our ‘test’ records, and moving the Lead Score and verifying that it works. Congrats! You’ve inserted an image into Salesforce using a formula.
Testing if the lead score is medium:
Testing if the lead score is high:
Has this helped you out at all? Let me know if the comments below! Also, if you have any other use-cases where you need to add an image that displays through Formula logic, please share it with me.