6

I'm trying to use the ISPICKVAL formula on a Visualforce page. I've assumed that doing so is better than just a straight text compare, since it will continue to work after the picklist entries have been translated (and maybe that's a big assumption).

Anyway, it's documented in the Visualforce Developer's Guide thusly:

Determines if the value of a picklist field is equal to a text literal you specify.

ISPICKVAL(picklist_field, text_literal) and replace picklist_field with the merge field name for the picklist; replace text_literal with the picklist value in quotes. text_literal cannot be a merge field or the result of a function.

Sounds great, but when I try this syntax in my Visualforce page (with a standardController of My_Object__c):

{!ISPICKVAL(My_Object__c.Status__c, 'Inactive')}

I get the following error:

Save error: Incorrect parameter type for function 'ISPICKVAL()'. Expected Picklist, received Text

The Status__c field is definitely a picklist, and 'Inactive' is one of the options.

What am I doing wrong? And should I just give up and replace it with My_Object__c.Status__c == 'Inactive' (which I expect would stop working if that field is translated, but maybe I'm wrong)?

1
  • 1
    It's interesting because I've definitely used ISPICKVAL before in Visualforce, but it was slightly different. The picklist was on a global variable as opposed to a standard controller field: ISPICKVAL($User.UserType,'Guest'). Commented Mar 12, 2013 at 2:46

2 Answers 2

4

When you access a picklist on a Visualforce page using the normal annotation like My_Object__c.Status__c, the page treats that field like a String.

The same issue can be found on the Developer Boards on more than one occasion. Your best bet is to create a formula field to do what you want and access it that way or access it using the == annotation.

2

Assuming Status__c is in fact a picklist then this looks valid to me.

That said, given that the comparison parameter is a text literal I really don't think this is going to work for translated picklist ('d love to be wrong on this but my hunch is otherwise) values so my suggestion would be to just use a comparison for now.

You must log in to answer this question.

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