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.
- You need to include the file extension (e.g. .jpg, .gif);
- 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
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.