Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

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.

share|improve this answer
    
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 '13 at 4:30
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
    
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 '13 at 17:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.