Wednesday 3 April 2013


Using Your Own Image in an IMAGE() Formula

Let's say for the sake of argument that you wanted to be able to visualize the gender of a Contact without having to actually, you know, read the Contact record. With all of these people named Chris and Pat, the possibility exists that you will address Pat Evans as "Sir" when her call pops up on your screen.What to do?
One (fairly silly) approach is to create an IMAGE() formula field on the Contact record that returns a different cartoon icon depending on the value in the Gender picklist field. These images are obviously not part of the hidden cache of images that Salesforce provides, so the first thing we will have to do is upload these images as Documents.
If you don't already have a public Documents folder designated for holding public, shared files, go ahead and set one up. On my system, that folder is named "Shared Documents". Next, upload your images into this folder; remember to mark each file as an Externally Available Image:

The next step is to go to the Shared Documents folder and look up the URLS for these images. To do this, click the View icon next to each image and look at the address bar for the URL for each image.Salesforce, by default, does not identify the gender of a Contact - but this is something I generally add as a custom field to help avoid this very issue. (Please do remember that the correct label here is "Gender" and not "Sex".) As you can imagine, this is a picklist with two values, "Female" and "Male". If defaulting one of these values makes sense to you, feel free.
The next step is to create a new IMAGE() field that looks up the correct Document depending on the value in the Gender field:
IF(TEXT(Gender__c) = 'Male', 
IMAGE('/servlet/servlet.FileDownload?file=015E00000011lyE', 
   'Male', 64, 64),
IMAGE('/servlet/servlet.FileDownload?file=015E00000011lyJ', 
   'Female', 64, 64))
Notice that we omit the Salesforce domain entirely - SFDC will handle that for us automatically. The second argument for IMAGE() is the alt-text, which is not the same as the title text. (I include it here mostly so we can tell which file is which.) I sized the images to match the actual size of the icon, 64 x 64, but you could load a larger image and resize it in the IMAGE() function.Here's how it looks for a man:

And a woman:
Categories:

0 comments:

Post a Comment

    Links