0

I have a picklist field.

When the field value is x, the color should be yellow. And when its value is y its color should be orange.

How to change the color of the output text based on picklist values in Salesforce? How do I implement this?

1 Answer 1

1

You can use the CASE formula on the output text's style attribute, like the following:

<apex:outputText
          value="{!Account.AccountSource}"
          style="color: {!CASE(Account.AccountSource, 'Web', '#f0f', '#000')}">
</apex:outputText>

This will turn the text pink when "Web" is selected as the Account Source.

Please remember to add a actionSupport tag to your picklist element so that the page can rerender when the option is changed, like this:

<apex:inputField id="field1" value="{!Account.AccountSource}">
    <apex:actionsupport event="onchange" rerender="mainform"/>
</apex:inputField>
2
  • Why are you putting #000 there? it is appearing in black color and color is not changed.
    – SFDC
    Commented Aug 17, 2017 at 12:19
  • The first argument of the case formula is the field to be evaluated, followed by the value to be compared and the output to that specific value. The last argument (#000) is the default when the value does not match any of the previously specified values. Commented Aug 17, 2017 at 12:28

You must log in to answer this question.

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