[SalesForce] Using Custom Label in Custom Formula Fields

We have a formula field that displays images based upon the custom object's record type and a picklist value.

This formula field is like

IF( $RecordType.Name = "XYZ", IMAGE( 
CASE( 
Status__c , 
"FIRST","/resource/first", 
"SECOND", "/resource/second", 
"THIRD", "/resource/THIRD", 
"/s.gif"), 
"DEFAULT")

The above works well and displays images as expected.

We want to explore whether instead of using "FIRST", "SECOND" etc..can we use custom labels.

The custom label's name is First and its value is FIRST.

I tried the following without success

1)

IF( $RecordType.Name = "XYZ", IMAGE( 
CASE( 
Status__c , 
$Label.First,"/resource/first", 
"SECOND", "/resource/second", 
"THIRD", "/resource/THIRD", 
"/s.gif"), 
"DEFAULT")

Result : Getting the following error

"Error: Incorrect parameter type for function 'CASE()'. Expected ,
received Text"

2)

 IF( $RecordType.Name = "XYZ", IMAGE( 
CASE( 
TEXT(Status__c) , 
$Label.First,"/resource/first", 
"SECOND", "/resource/second", 
"THIRD", "/resource/THIRD", 
"/s.gif"), 
"DEFAULT")

Result : Formula field gets successfully compiled but the image is not being shown.

I searched online and I could not find any actual examples of $Label being used in formula fields though there are examples of $Label being used in VF pages.

Can someone help me on this ?

Best Answer

I did this a very different way...

So rather than use a Formula field to do this I use a workflow rule with a field update. The amount of space in the field update is much greater so your statements will not be an issue.

In fact I use this method to check the difference between the Product total amount (roll up of Opportunity Line Item) and the Estimated Revenue that the Opportunity Owner enters manually (this being their best idea of the value of the opportunity at any given step).

We check the month, quarter and year of the opportunity, check whether the value is above or below a certain threshold and the line of business and the end response sets a field (called RedAmberGreen__c) that is not on their page view and then I use a formula field to show either a red, amber or green light.

Related Topic