+ Start a Discussion

Can we achieve the following with Formula field...?


I have the following task...

We have a pick list containing colors (red,green,blue...)
We have another field which changes its Backgound color based on the color selected from first field...

I need to achieve this without code...

Can i use formula field...? If yes then what would be the formula...?
Best Answer chosen by Vempally
Anupam RastogiAnupam Rastogi
Hi Vempally,

Currently this feature (of conditionally formatting field background color) is not available in Salesforce. Refer Idea: https://success.salesforce.com/ideaview?id=08730000000BrPbAAK.

But I had a similar requirement in my project which I implemented as follows. This is not a work around but the actual way to have such requirements implemented using the present Salesforce configurations.

1. For all the pick list values of the controlling field (i.e. all the color values), upload the respective images having the colors at Set Up -> Develop -> Static Resources.
2. Create a new formula field for the concerned object with the following format:
     CASE(expression, value1, result1, value2, result2,...,else_result) 
     Here, replace expression with the controlling picklist field that holds the color value.
     Replace value1(2, 3... and so on) with the controlling field picklist values like Red, Green, Blue etc
     Replace result1(2, 3... and so on) with the IMAGE function referencing the image files that you uploaded. To get the URL to these files go to: Set Up -> Develop -> Static Resources -> Click the file name -> View File. Copy the content from "/resource/........". This is the URL to be provided in the IMAGE function.
     Replace else_result with a default image file that you wish to show in case no color value is selected

To help you better understand, here is what I have in my application. We have the Case Status field that can have values like New, Escalated, Closed. We have another field that should show a corresponding image based on the Status field. So I have uploaded three images in Static Resources for each of the three Status field values. And the formula field goes like this
    CASE( Status , 'New', IMAGE("/resource/1428299014000/NewCase", "New Case"), 'Escalated', IMAGE("/resource/1428299132000/EscalatedCase", "Escalated Case"), IMAGE("/resource/1428299465000/ClosedCase", "Closed Case"))

I hope this helps.


If you find the reply useful that solves your problem then please mark it as best for others to benefit.