I had to put together a salesforce demo recently in which I wanted a field to display a flag depending on the value of another field. Here’s the scenario:

If a certain checkbox is ticked, I wanted my field to show a green flag, otherwise I wanted it to show a red flag. Turns out its actually pretty easy with salesforce. Here’s how to do it:

Create a Formula Field of type TEXT where you want your flag to appear. In the body of the formula type the following:

IF (
	 IMAGE("/img/samples/flag_green.gif", "Green Flag"),
	 IMAGE("/img/samples/flag_red.gif", "Red Flag")

What this code does is check if the custom field Flag_Set__c is checked. If it is it emits the HTML required to display a green flag, which is part of any stock salesforce org. If it is not checked a red flag will be displayed.

Add your field to your Page Layout and you’re done! Here are some screenshots:

Picture 4.pngPicture 5.png

You can extend this to display any image you want depending on whatever criteria as long as you can express it in the body of the formula. You’re also not limited to stock images as you can upload whatever you want to your salesforce instance or make your image tags point to wherever (flickr, S3, etc).


Leave a Reply