function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
amitashtekaramitashtekar 

How to display picklist values on the visual force page without writing any code.

I want to show the picklist value for global variable User on a visual force page.

 

But it is showing me incorrect parameter.

 

I have written code within vf as

 

<apex:outputlabel value="{! TEXT($User.UserType) }"/>

 

Does anyone knows how to do it.

I have tried different things.

I dont want to write any apex code for it.

Best Answer chosen by Admin (Salesforce Developers) 
sebcossebcos

Hi,

from the help:

Picklist fields can only be used in the following functions:

  • ISPICKVAL—Compares the value of a picklist to a single value.
  • CASE—Compares the value of a picklist to multiple values.
  • TEXT—Converts a picklist value into a text value so that you can work with the value in functions that support text value, such as CONTAINS. (Only available in formula fields, validation rules, and workflow field updates.)

Apparently TEXT function is not available in visualforce. But you can use the CASE function like so:

 

{!CASE($User.UserType,'Standard','Standard','default')}

All Answers

sebcossebcos

Hi,

from the help:

Picklist fields can only be used in the following functions:

  • ISPICKVAL—Compares the value of a picklist to a single value.
  • CASE—Compares the value of a picklist to multiple values.
  • TEXT—Converts a picklist value into a text value so that you can work with the value in functions that support text value, such as CONTAINS. (Only available in formula fields, validation rules, and workflow field updates.)

Apparently TEXT function is not available in visualforce. But you can use the CASE function like so:

 

{!CASE($User.UserType,'Standard','Standard','default')}

This was selected as the best answer
BrianWKBrianWK

You're already using ApexLabel. I'm guessing that the UserType is a field on the User object. I'm not sure you'll get the right output but could you do something like this:

 

<apex:outputlabel>
    <apex:outputfield value="{!$User.UserType}" />
</apex:outputlabel>

 

I'm assuming here that you want to use the field value as your label.

amitashtekaramitashtekar

It can be used to display the usertype if you have three choices known.

Thanks sebcos.

CASE function helped me a lot.

 

amitashtekaramitashtekar

Hello BrianWK,

Thanks for reply.

But it doesnot work.

johannjohann

The case function worked for me - it's a little awkward but it works!