The Correct Way of Using Custom Images in Salesforce Formula Fields

The Formula Field in Salesforce is a powerful tool to show data using automatic calculations. An example would be to show the average assessment score after a business review.  Formula Fields can also be used to display images based on some logic. Salesforce provides a few images to use in Formula Fields. Standard images include images of traffic lights for status, color squares, stars and horizontal bars. More details of Image Link Formulas can be found here.

Salesforce also provides a way for you to use custom images. For instance, you want a special image/icon to display specific information like a bigger traffic signal circle or a set of horizontal bars to indicate red/amber/green status as shown below.

Use of Red/Yellow/Green Circles in Images

Use of Yellow/Green Horizontal Bars

 

Standard Way

To use your own custom image, you can upload it in Salesforce Files or install the Graphics Pack from Salesforce and add many more image options. Salesforce provides instructions on how to use these external images in Formula Fields here. Each file will have its own ID which will be different in each org. This approach is fine if you are directly using these images in production in a couple of columns. This approach breaks down if you are using images in multiple objects and are developing in a Sandbox or Developer org to be moved to production at regular intervals.

Correct Way

The correct way to use custom images is to upload images as static resources. You can even zip related images and add the entire zip file as a static resource. Then reference the images in Formula Fields as shown below

  • Formula to use when Image is used in Static Resource: IMAGE(“/resource/resource_name”, “Image Tooltip”)
  • Formula to use when zip file is used in Static Resource: IMAGE(“/resource/<static resource name>/filepath_in_zip”, “Image Tooltip”)

With this approach, you just need to include the static resources in your packages or change sets. There is no need to upload images separately which simplifies your packaging and deployment.

Team Varasi