Configuration

Displaying Images using Salesforce Formula Fields

Displaying Images using Salesforce Formula Fields
We all have used formula fields for  calculations, Looking up values  from linked objects and for everal  other use cases. But have you ever  used it to display images ??

 If Not, Than you have landed to the  right post.



Formula field evaluates the logic and displays the result on to the screen. Images from the static resource ,Public web URL can be displayed as results by Using IMAGE Function


Examples Below: 

Flags

Suppose you have a Picklist Field (Api Name = Priority__c) with values as High,Medium and Low . You can display different colour flag for different picklist values using formula field.
Create a formula field with Text as return type value and copy paste the below code in the formula editor : Change the highlighted text with your picklist fields api name.
IMAGE( 
CASE( Priority__c
"Low", "/img/samples/flag_green.gif", 
"Medium", "/img/samples/flag_yellow.gif", 
"High", "/img/samples/flag_red.gif", 
"/s.gif"), 
"Priority Flag")


Trafic Lights

Traffic Lights can be displayed using the formula field, lets assume you have a Status picklist field with values Red,Green and Yellow. Create another formula field to represent the Status Pictorially . Use the below mentioned formula.Change the highlighted text with your picklist fields api name.

IMAGE( 
CASE(Status__c
"Green", "/img/samples/light_green.gif",
"Yellow", "/img/samples/light_yellow.gif",
"Red", "/img/samples/light_red.gif", 
"/s.gif"), 
"status color")


Rating Stars

Formula fields can even be used to display Rating Stars. Assume the Rating picklist field has values from 1-5.  Create a formula field and enter the code as mentioned below in the formula editor.Change the highlighted text with your picklist fields api name.

IMAGE( 
CASE(Rating__c, 
"1", "/img/samples/stars_100.gif",
"2", "/img/samples/stars_200.gif",
"3", "/img/samples/stars_300.gif", 
"4", "/img/samples/stars_400.gif", 
"5", "/img/samples/stars_500.gif", 
"/img/samples/stars_000.gif"), 
"rating")

Image from URL

Images from the URL field can also be displayed using formula fields. Lets say the API name of url field is Image_url__c , than use the below mentioned code to create a formula field which would display the image. Change the highlighted text with your URL field api name.

IMAGE( Image_URL__c ,"Image from the URL ",200, 200) 

Image showcasing all the mentioned formulas above

Displaying Images using Salesforce Formula Fields

About Saurabh Dua

10 comments:

  1. FYI - Salesforce provides a bunch of images out-of-the-box for your use.

    I found this excellent collection yesterday when tackling just this need:
    http://free-121d5f44d20-121d603d1c5-121ee2b8103.force.com/force2b/salesforceicons

    ReplyDelete
  2. Hi if we want to insert images of local system in field then
    and i am unable to get images in my field

    ReplyDelete
    Replies
    1. You can upload images from your local system to static resources or documents and then use them in your formula fiedls

      Delete
  3. Give Some Example for Image from URL

    ReplyDelete
  4. Displaying Images using my sincere thanks for sharing this post Please Continue to share this post
    Salesforce Training in Chennai

    ReplyDelete
  5. Hi Saurabh, Thanks for this great post. I am trying to display an image from an external URL, just like in your last example. However, my image isn't showing up. I have two fields, one Text field that stores the URL and another Formula field where I reference the URL field api name as you suggested. The reference is working (meaning I can click the field and it opens the image in another window), but the image won't display in Salesforce. Any idea why?

    ReplyDelete
    Replies
    1. Hi,

      Try using the below formula and see if the image is showing up. There might be access issues with your image.

      Fill the url field with

      https://4.bp.blogspot.com/-9AiICmwE1_c/VznrZjSnEDI/AAAAAAAAAJw/HXyS7ZptxSUm3GZhmJw0BexpNZC8xB5hQCLcB/s1600/-downloadfiles-wallpapers-1280_1024-here_we_go_wallpaper_formula_1_cars_wallpaper_1280_1024_2244.jpg

      the formula field should use the below formula.

      IMAGE( Image_URL__c ,"Image from the URL ",200, 200)

      Verify if this works ?

      Delete

Powered by Blogger.