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
mathewsmathews 

Pick list values

Hi All,

Any one knows how to access picklist values of a field in an Object ?

Thanks in advance.

Message Edited by mathews on 10-10-2007 06:55 AM

Best Answer chosen by Admin (Salesforce Developers) 
mtbclimbermtbclimber
I'd check your controller again. I just built this page/controller to demonstrate what it sounds like you are trying to accomplish.

my_picklist__c is a picklist on foo__c:

Code:
CONTROLLER:

public class myCon {
  public foo__c getFoo() { return new foo__c(); }
  public void setFoo(Foo__c f) {}
}

PAGE:
<apex:page controller="myCon">
  <apex:form>
    <apex:inputField value="{!foo.my_picklist__c}"/>
  </apex:form>
</apex:page>

All Answers

mtbclimbermtbclimber
What are you trying to do?

If you bind a picklist to the inputField component it will get the values automatically.
jpizzalajpizzala
Andrew,

As per my understanding (and correct me if I'm wrong), but the picklist values will only be populated if you bind them to an inputField component using a standardController. Is there any way to grab the picklist values of a field using a custom controller? With the API you can grab this information with a describe call, is there something similar with Apex Code?
mtbclimbermtbclimber
Happy to correct you here :)

inputField will work with any controller. It is aware of the field type and other field level attributes directly and is not controller dependent.

Notably, you can use custom classes with standard controller starting int winter '08. While that really doesn't change things here I thought you might be interested to know that as you are probably dropping into custom controllers because you need to do some things the standard controller won't let you do. In winter '08 you can have the best of both worlds.

Regards,
jpizzalajpizzala
Thanks for the insight! I don't think I was specific enough in my previous post, however. What we are trying to do is (using a custom controller until Winter '08) output a picklist field from a custom object. Using Andrew's suggestion I was able to recreate the picklist with appropriate values for SF-native fields (such as {!case.type}), but when applying similar logic to fields on custom objects, the field is not recognized:

Code:
<apex:inputField value="{!timed_item__c.work_type__c}"/>

Error: Unknown property Timer.timed_item__c
Create apex code method Timer.getTimed_item__c
Is this something that is possible now or will I just have to wait for the extensions capability in next month?

Thanks again!

 

mtbclimbermtbclimber
I'd check your controller again. I just built this page/controller to demonstrate what it sounds like you are trying to accomplish.

my_picklist__c is a picklist on foo__c:

Code:
CONTROLLER:

public class myCon {
  public foo__c getFoo() { return new foo__c(); }
  public void setFoo(Foo__c f) {}
}

PAGE:
<apex:page controller="myCon">
  <apex:form>
    <apex:inputField value="{!foo.my_picklist__c}"/>
  </apex:form>
</apex:page>

This was selected as the best answer
jpizzalajpizzala
Thanks! That's exactly what I needed.