10

I'm currently gathering metadata on fields using a controller and was investigating using Dynamic Visualforce Bindings instead. I can see that I can iterate through a controller-supplied list of fields like this:

<apex:repeat value='{!fieldList}' var='field'>
    console.log('$ObjectType[object].Fields[field].Name} = {!$ObjectType[object].Fields[field].Type}');
</apex:repeat>

to list the names and types of the controller-supplied field list. The manual only describes a handful of attributes, but I discovered that if I generate a WSDL for my org, under the definition of "Field" I can see a list of other choices such as autoNumber, calculated, etc. which do seem to work. One attribute of great interest to me is picklistValues, but unlike the simpler fields I haven't succeeded in using it in a page. I tried this:

<apex:repeat value="{!$ObjectType[object].Fields.MyPicklistField__c.picklistValues}" var="val">
</apex:repeat>

but that produces a Visualforce error: "Unsupported type common.api.soap.wsdl.PicklistEntry".

Is there any way to get the picklist values for a field through Dynamic Visualforce Bindings?

2
  • Did you find a solution for this ?
    – snehakem
    Feb 19, 2016 at 8:03
  • 1
    @snehakem no, at the time the answer from Greg Grinberg seemed definitive. You can get the information from the controller anyway. Furthermore these days there are better ways to handle lists of fields in a generic way.
    – Jeff Trull
    Feb 23, 2016 at 5:53

4 Answers 4

7

This is impossible to do even with regular visualforce. The following page will give you the same error at compile-time that you see at runtime with dynamic vf.

<apex:page>
    {!$ObjectType.Account.Fields.Industry.PicklistValues}
</apex:page>

I ran into this issue about a year ago and there is no workaround except returning the list of picklistEntries from the controller. Ex:

<apex:page controller="picklistentryController"> 
    <apex:repeat value="{!entries}" var="val">
        {!val.label}<br/>
    </apex:repeat>
</apex:page>

public with sharing class picklistentryController 
{
    //for dynamic vf simply build a map of fieldnames to lists of picklistentries,
    public list<Schema.Picklistentry> getEntries(){
        return Account.fields.Industry.getDescribe().getpicklistvalues();
    }   
}

NOTE: If you are supporting multiple languages and using the apex:page lang parameter to set the language of the page anything referenced in apex (picklistentry labels in this case) will ignore the parameter and be returned in the language of the running user instead.

1
  • That's it, then! No choice but to get the metadata from the controller... Maybe someday I'll use dynamic vf bindings - but not this time. Thanks.
    – Jeff Trull
    Feb 9, 2013 at 4:30
2

As Greg Grinburg says, it is impossible to achieve the result you want through dynamic VisualForce bindings alone.

However, it may be worth noting that your workaround can have an equivalent degree of flexibility if that flexibility is worth the verbose syntax.

Controller

class MyController
{
  public Map<String, Schema.SObjectType> schemaInfo 
  {
    get { return Schema.getGlobalDescribe(); }
  }
}

Page

<apex:page controller="MyController">
  <apex:repeat 
     var="pv" 
     value="{!schemaInfo['MyObject__c'].describe.fields.map['MyPicklistField__c'].describe.picklistValues}"
  >

    {!pv.label}<br/>

  </apex:repeat>
</apex:page>
1

I was trying to achieve the same thing and faced the same error "unsupported type common.api.soap.wsdi.PicklistEntry encountered" while compiling.

But there is another way to access the picklistValues, instead of passing a list of field names you can pass a list of DescribeFieldResult to the page, you then have access to the getPicklistValues method as defined in the Describe Field Result Methods.

0

There is an excellent post by Bob Buzzard on this specific issue and it covers picklistValues as well Record Type Specific Picklist Values

1
  • Thanks for the link, but as I mentioned I am trying to do this with dynamic visualforce bindings. Bob's post describes something different: controller methods for dependent picklists. If I can't do this as I want, I will certainly try doing it through the controller, but my goal is to use this feature.
    – Jeff Trull
    Feb 8, 2013 at 17:26

You must log in to answer this question.

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