Scenario: Display Images from static resource in formula field based on field value in Salesforce

 

When displaying image directly from static Resource
You don’t need to put any file extension like jpg, png, gif when you’re referencing the static resource itself (e.g. /resource/ImageFolder represents the static resource

IMAGE(image_url, alternate_text [, height, width]) ‘)

IMAGE( '/resource/happy', 'image')

Note: With File extension it wont work

IMAGE( '/resource/neutral.jpg', 'image')

Referring to image in formula field based on condition.

Sentiments__c is text field which can hold “positive”,”neutral” and “negative” value. Based on the value we want to display image. If image does not show up because of error then alternate text “emotions” will show in the formula field.

IMAGE(
CASE(Sentiments__c,
'positive', "/resource/happy",
'negative', "/resource/sad",
'neutral', "/resource/neutral",
''), "emotions")

Set height and width of image in formula field

IMAGE(
CASE(Sentiments__c,
'positive', "/resource/happy",
'negative', "/resource/sad",
'neutral', "/resource/neutral",
''), "emotions",260,250)

Important – Display Image from Zip File.

Lot of people get confused with the path when displaying image from zip file. Therefore, please understand the scenario completely.

  1. You need to include the file extension (e.g. .jpg, .gif);
  2. Make sure the folder path is correct, and observe the entire path as case-sensitive names.
IMAGE(
CASE(Sentiments__c,
'positive', "/resource/emotions/happy.jpg",
'negative', "/resource/emotions/sad.png",
'neutral', "/resource/emotions/neutral.jpg",
''), "emotions",250,250)

Output

Positive

Negative

Neutral

Reference

https://trailhead.salesforce.com/content/learn/modules/visualforce_fundamentals/visualforce_static_resources

 

Did you enjoy this article?
Signup today and receive free updates straight in your inbox.
I agree to have my personal information transfered to MailChimp ( more information )
50% LikesVS
50% Dislikes

1 comment on “Scenario: Display Images from static resource in formula field based on field value in Salesforce

  1. sai kiran

    Hi Smriti,
    Thanks for your sharing your knowledge. I tried accessing images through zip folder but it is not working.
    This is my formula.
    IMAGE(case(Origin ,
    ‘Email’, “/resource/amazon/image1.jpg”,
    ‘Phone’, “/resource/amazon/image1.jpg”,
    ‘Web’, “/resource/amazon/image3.jpg”,
    ”),
    “amazon”,25,25)
    Any help is highly appreciated.

Comments are closed.