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
ethanoneethanone 

Populate and retrieve values from visualforce picklist with custom object

I'm new to visualforce and I've got a custom object, Property__c with a multi-select picklist of classifications (Classification__c). How can I put those picklist values onto a visualforce page with a custom controller? And how do I retrieve the value(s) for use in a query?
Message Edited by ethanone on 03-26-2010 10:22 AM
Anand@SAASAnand@SAAS

 <apex:page controller="YourCustomController">

<apex:form><apex:inputField value="{!prop.Classification}"/></apex:form></apex:page>

 Controller:

 

public class YourCustomController{Property__c prop {get; set;}public YourCustomController(){this.prop = new Property__c();}}

 

You should think about using standard controller as well. 

 

 

ThomasTTThomasTT

I believe your point is "multi-select picklist". If it is about a general field, Anand's post is the answer.

 

The value set by the user in a multi-select picklist field is stored as a string with "; (semi-colon)" separator like "A;B;C".

If you want to understand or to create the value in the controller by yourself, you can assume the format with ";" and parse or format your value (don't mess it up).

 

In query, there are special where-clause expression for multi-select picklist (e.g. includes, excludes). See following manual.

 

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_querying_multiselect_picklists.htm

 

To query the multi-picklist field value, it's same as other field as a string.

 

ThomasTT

 

DEV_NAVATARDEV_NAVATAR

In the Custom Controller, you can create a apex selectlist.

 

On the page load, call the function which retrieves the values of that multi-picklist field. eg:

 

Schema.DescribeFieldResult fieldResult = Property__c.Classification__c.getDescribe();

 

List allValues = fieldResult.getPicklistValues();

 

Now, you can return the list of values to your VF page.