2

Been trying to figure this out the whole day. I am new to VF and would like some assistance in figuring this out.

I have a number value on a visualforce page that I would like to style with RAG colors dependant on the value. Less than 50=red Between 50 and 74=amber More than 74=green

So far I have been able to figure out that this can be done through the font styling. However, I have only been able to do the red and green. Not quite sure how to add in that third condition that will make the text turn amber through the visualforce styling. Below is what I have for the style attribute:

color:{!IF(cObject__c.FieldName__c < 50, 'red', 'green')}

Your assistance is greatly appreciated. Thanks!

  • Miguel
3
  • Look at the documentation for the CASE function. Commented Aug 10, 2016 at 22:16
  • 1
    Nevermind, that won't work. Just use IF(cond1, val1, IF(cond2, val2, val3)) Commented Aug 10, 2016 at 22:16
  • @CharlesKoppelman You can indeed use case. Just requires a bit of outside-the-box thinking.
    – sfdcfox
    Commented Aug 10, 2016 at 22:42

2 Answers 2

2

Just use:

{!IF(cObject__c.FieldName__c < 50, 'red', IF(cObject__c.FieldName__c < 75, 'goldenrod', 'green'))}
1
  • Thanks Adrian, this worked perfectly. Didn't know "goldenrod' was a thing. ...The more you know. Thanks again. Commented Aug 11, 2016 at 15:50
0

In this specific circumstance, you could actually use case:

{!CASE(MAX(0, FLOOR(cObject__c.Field_Name__c/25)), 0, "red", 1, "red", 2, "goldenrod", "green")}

This works because we divide by 25, so 0 and 1 cover 0-49, 2 covers 50-74, and the default value is green, which is 75 or more; this code is also capped at 0 using MAX.

1
  • a nice solution for deciles as well
    – cropredy
    Commented Aug 10, 2016 at 23:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .