Admins

Use Images in Salesforce Formula Fields to Spice up Your Org

By Lucy Mazalon

Salesforce image formula fields display image icons to Salesforce users according to the field value/s a record has, instead of calculating a number, or outputting a string of text. Simply speaking, the formula statements will ask: “if this equals [some value], show [image A], if not, show [image B]”. This is a basic, two-line example, and you may already know that Salesforce formulas can be several lines long, to switch between different images in formula fields.

Image formulas in Salesforce are a great addition to your org to help users to digest information quickly on records or list views, and bring their attention to what’s important. Salesforce image fields can be tricky to apply on your first few attempts, which is why we’ve included Salesforce image formula examples to get you started.

How Do I Use a Graphics Pack in Salesforce?

Let’s begin by downloading the Salesforce Graphics Pack from the AppExchange. Thanks to our friends over at Salesforce Labs, we instantly have a whole host of icons to play around with.

Access your Salesforce image library by heading to the App Launcher (waffle icon), and searching “Lightning Graphics Pack”:

This launches an icon library with several tabs (‘Farm Fresh’, ‘Icon Shock’, ‘Tango Desktop Project’, etc. are icon developers. The icons are not categorized in any other way). Take a look around, there are hundreds to choose from!

How Do I Apply an Image Formula in Salesforce?

In this tutorial, we will add an “Account Health” formula field, based on the standard “Rating” picklist field.

What is a Formula in Salesforce? If you’re new to formulas check out this Trailhead module.

Step 1: Create a custom formula field

In Salesforce Setup, head to the Object Manager → Account → Fields & Relationships → ‘New’ (button).

  • Choose the field type: Formula
  • Field label: Account Health
  • Formula Return Type: Text*

*note there is no option for ‘image’ return type, which often trips people up.

Step 2: Write the Salesforce image formula

Here’s the whole formula and what each part of the formula means:

CASE(Rating, 
"Hot", IMAGE("/resource/1523798147000/GraphicsPackNew/silk/16/silk/medal_gold_1.png", "Hot"), 
"Warm", IMAGE("/resource/1523798147000/GraphicsPackNew/silk/16/silk/medal_silver_1.png", "Warm"), 
IMAGE("/resource/1523798147000/GraphicsPackNew/silk/16/silk/medal_bronze_1.png", "Cold"))
  • CASE: a Salesforce formula function where you have multiple statements relating to picklist field values. In this example, the formula is asking “if the rating is “Hot” then show [image A], if the rating is “Warm” then show [image B], if the rating is “Cold” then show [image C]”.
  • IMAGE: indicates you are about to reference an image file.
  • “/resource/… : the image URL. Clicking on an icon in the Graphics Pack will open the file in a new tab. That tab contains the URL, eg. [your domain]/resource/1630492553000/GraphicsPackNew/fatcow/farmfresh/16/film.png
  • “Hot”: you see the picklist value repeated after the image URL – that’s known as the Alt text. That will appear to the user in case the image doesn’t load properly, so is a good fallback option.

Before you write your formula, pick out the graphics you want to use, and list out the image file URLs and picklist values. Copying and pasting from your notes will make building the formula in the formula editor clearer.

Click “Check Syntax”, which will check your formula is written correctly and references fields that exist.

Step 3: Test the logic

Test all scenarios by selecting each picklist value at a time, clicking save, and checking the icon you expect appears on the record.

Note: the icon won’t change until you save the record.

Step 4: Add the icons where users need it

Add the image formula field to:

  • Record pages
  • The highlights bar on record pages
  • List views
A list view with an image formula field added.

Salesforce Image Formula Examples

Account Health Rating

The example in the tutorial was based on the standard “Rating” field, however, your organization may have another definition of what a ‘healthy’ account looks like. Could it be the last activity date? If they are approaching the end of a contract, and there’s no renewal opportunity being worked on?

Case Status Image

Quickly show which Cases need attention with a simple image field based on Case “Status”:

CASE(Status, "New", IMAGE("/resource/1523798147000/GraphicsPackNew/silk/16/silk/star.png", "New"),
"Working",IMAGE("/resource/1523798147000/GraphicsPackNew/silk/16/silk/comments.png", "Working"),
"Escalated",IMAGE("/resource/1523798147000/GraphicsPackNew/silk/16/silk/flag_red.png", "Escalated"),
IMAGE("/resource/1523798147000/GraphicsPackNew/silk/16/silk/heart.png", "Closed"))

Lead Score

If your users have a high volume of leads to work through, help them prioritize who’s worth talking to by highlighting sales-ready prospects, leads from target accounts, or that fit your ideal customer profile.

The most simple version is to base the formula on the standard “rating” field.

If you use a marketing automation platform, it almost certainly has lead scoring functionality (usually a number) that can be synced across to Salesforce. This tutorial shows you how to create a Salesforce star rating formula fields for Pardot Prospect score:

Mailability Flags

Another of my favorites to add to Salesforce orgs is flags to make communication preferences highly visible. Not only does this stop users contacting people who have opted out, it also helps sales and marketing teams work together (this is because marketing emails are treated differently to one-to-one contact).

Display a coloured flag on the Lead or Contact record in Salesforce according to the channels you want to cover (email, phone SMS):

In this example, the colour flags apply as follows:

  • Green = If not opted out of any
  • Orange = IF Opted out of Email OR Phone OR SMS
  • Red = If not opted out of all (Email AND Phone AND SMS)
IF
(HasOptedOutOfEmail = TRUE && DoNotCall = TRUE && SMS_Opt_Out__c = TRUE,
IMAGE("/img/samples/flag_red.gif", "Red Flag"),
IF
(HasOptedOutOfEmail = TRUE || DoNotCall = TRUE || SMS_Opt_Out__c = TRUE,
IMAGE("/img/samples/flag_yellow.gif","Yellow Flag"),
IMAGE("/img/samples/flag_green.gif","Green Flag")))

Read this tutorial for more examples: Create Mailability Flags in Salesforce for Highly Visible Communication Preferences

Final Thought

Now that you’ve seen the power of image formulas, ask yourself the question, “Where can my users benefit the most from images?” You don’t want to use images for the sake of it, but to help users get a glimpse of the status of their data.

The Author

Lucy Mazalon

Lucy is the Operations Director at Salesforce Ben. She is a 10x certified Marketing Champion and founder of The DRIP.

Comments:

    Salesforce Tom
    April 16, 2018 3:02 pm
    you can also use gifs if you like it 'muy caliente'
    Sean
    April 16, 2018 5:18 pm
    Thanks for the post - I didn't know this and I already know where I'm going to use this for our org.
    Imran Battla
    April 16, 2018 7:22 pm
    Did you have to include an else result in the case statement? I've included the "Not Found" to close the statement.
    Ivan
    April 17, 2018 7:56 am
    Thanks for the useful information. And is it possible to add your images or can I use only images from the Graphics Pack?
    Nicolas COMMEAUX
    April 17, 2018 1:08 pm
    Thanks for these examples ! Formulas are also a good way to display "Progress bars" thanks to 3 "One pixel images" and a simple formula : IF (Amount_Realized__c > Amount_Objective__c, IMAGE('/resource/green', 'Test', 15, 100), IMAGE('/resource/blue', 'Test', 15, Amount_Realized__c/Amount_Objective__c * 100) & IMAGE('/resource/grey', 'Test', 15, (100 - Amount_Realized__c / Amount_Objective__c * 100 )))
    Arnaud
    April 17, 2018 7:49 pm
    Hello, i've just test this package and your example are not working. to have image into your formula field you have to launch Document ID of your image and URL of your image for Example to have medal on your leads you have to create formula field like this: CASE( Rating , "Hot", IMAGE("/servlet/servlet.FileDownload?file=0150Y000001kngV","Hot",16,16), "Warm", IMAGE("/servlet/servlet.FileDownload?file=0150Y000001kngb","Warm",16,16), "Cold", IMAGE("/servlet/servlet.FileDownload?file=0150Y000001kngP","Cold",16,16), "")
    Ben McCarthy
    April 17, 2018 9:23 pm
    Thanks for that, I'll have to try it myself.
    Nicolas COMMEAUX
    April 19, 2018 8:54 am
    @Arnaud : Your solution is also working but you really should use Static Ressources instead of Documents to avoid IDs directly in your formula that is hard to maintain when you deploy from an Org to another.
    Pablo Ramos
    April 27, 2018 7:08 am
    Thanks a lot! Very useful info!
    Mario
    June 11, 2018 12:46 pm
    Hello Ben, I am trying your solution but I only seem to get So I see the code instead of the image itself. I tried Html in formulas earlier without an issue but it seems that since the summer 18 this is not working? I use this in a custom Activity field. Any advise on this? Kind regards, Mario
    Idan
    August 06, 2018 8:41 am
    Hi Ben and thanks for this. I'm trying to show an image in the SF1 default page view using formula field + image etc. with no luck. Did you mange to do this somewhere successfully? Many thanks
    Andrea
    September 17, 2018 12:02 am
    Hi Ben, That is great, I did in the past for status and other simple indicators, and I was actually thinking about implementing this to fulfill some visibility need for my users. We need to find a way to flag to users that the Case has an attachment, I wanted to do this on the ListView. So when they are looking for their queues, they know right away instead of going to the Related tab and scrolling down to the files related list. Have you come across with any Clip image, you the one that indicates attachments? Have you any suggestions on how to achieve this solution?
    Juan Fach
    April 30, 2019 1:19 pm
    Could be possible to use different images like https://www.flaticon.com/ ?
    atlascan
    May 20, 2019 7:48 am
    Got it working by using the full url in the image field. Might want to update on that Ben.
    Vspruyt
    March 03, 2020 11:27 am
    This is great for fields that aren’t used in communities. I don’t think this is possible for a community as it is not hosted on your salesforce instance. Be sure to keep this in mind when setting up requirements!
    Edward Santandrea
    April 20, 2020 2:39 pm
    WHERE are these images stored in Salesforce, meaning Documents, Files, etc? I am in an existing org, with an existing formula field that does reference a "/resource/" based image link (but it does not reference "GraphicsPackNew", and its not in Installed Packages), so these are images uploaded to Salesforce separately to support this formula field, but I am having a heck of a time finding them (as a file, the formula displays the images properly). I've looked in Files > Asset Library as well as Documents. Any suggestions?
    Donna
    May 07, 2020 5:18 pm
    Now that LEX using FIles, I can't seem to get this work with uploaded images, whereas I was able to do this without issue when using Documents. So frustrated!
    Allan Cayapado
    May 22, 2020 10:23 pm
    You have to install the Graphics Pack first after that all images are stored in Graphics Pack tab
    Hanna
    September 01, 2021 3:59 pm
    We've been using this functionality for Cases for several years, to save space on the UI. Combine Status, Case origin, Priority and Record Type images into one formula field. This way we don't have to add each field separately on the Lightning Page layout quick view for agents, making for a more compact view of essential information.
    Dave Galloway
    September 01, 2021 7:31 pm
    You can combine these formula fields to create a multi image field and then use the one field vs. 3, 4, 5. If you set this up right with the naming you can have nested sorting based on the the combo. (Status, Severity, Account Type, Channel) Summary_Icon__c = Icon1 & Icon2 & Icon3
    Mike M
    September 02, 2021 6:37 pm
    Yes you can add your own images to Static Resources. Go into setup and search for Static Resources, and click the new button.
    Kam Jannati
    September 05, 2021 9:45 pm
    Hi everyone and thank you Ben for this article! I thought I would highlight that the images do not pull through when a record is mentioned in the new Microsoft Teams Salesforce app. Otherwise this works great! Kam
    Sophia
    September 30, 2021 10:44 am
    Hello, I tried to download the package but I have an error message appearing. Have you ever faced this issue before ? Duplicate Name The name "Graphics_Pack_for_Tabs/events_png1.png" is already used on component type: Document. Please rename existing component.
    Kelsey
    October 11, 2021 3:57 pm
    Just a quick clarification, can these fields be used in dashboards? I tried grouping by a formula field with both a flag image in it and text, but the dashboard group has the image resource name in it. It's a bummer, I might need to build a separate field for reporting but just wanted to double check that I wasn't missing something. The formula works beautifully on list views and record pages.
    Vandana
    December 22, 2021 6:50 am
    What happens if I get an 'out of room on the formula error' any workaround?
    Mark Laing
    October 14, 2022 7:24 am
    Hi Dave, This sounds really cool!!! Would you be willing to share how you configured this one?
    bijal
    January 13, 2023 6:17 am
    3. Create a formula field in opportunity called “SLA Status” as a Text field to check the related Account SLA Values and display an emoji () for SLA platinum Account, () Silver , for Bronze (), Gold () in opportunity. anyone help me how can I archive this step by step
    bijal
    January 13, 2023 6:21 am
    3. Create a formula field in opportunity called “SLA Status” as a Text field to check the related Account SLA Values and display an emoji () for SLA platinum Account, () Silver , for Bronze (), Gold () in opportunity. can anyone help me how can I archive this step by step
    Abi
    March 08, 2023 2:27 pm
    Hi Ben, How do I use images in formula field to surface images in communities?
    Andreea D
    March 29, 2023 6:28 am
    Hello Abi, It would work in a similar manner with using the formula field and ensuring users have access to it, make sure to consider where the image is coming from. Check out this example of an user who was trying to display a barcode in the Community, but it was creating issues as the source was not added as a trusted site : https://developer.salesforce.com/forums/?id=9062I000000XppiQAC Thank you!

Leave a Reply