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
TraciKimTraciKim 

No picklist values on my visualforce page

Hello,

I'm not a coder by any stretch, but I've been dabbling a bit to see if I can learn. We currently have a customer Lead convert page in our org where I'd like to add a field for "Qualifying Reason" (a custom picklist that has been created on the Lead). I mimicked some existing code to get the field on the visual force page and I tried to update the controller, by mimicking existing code as well.

What I get is a field for "Qualifying Reason" and picklist box with no values. From researching around, it looks like I need additional coding in my controller to pull the values, but my various attempts to do so have only created errors for me...

Can anyone provide any gudiance here?

Thank you!!!
TK


Visual Force Page:
                <apex:pageblocksectionitem >
                    <apex:outputlabel >Converted Status</apex:outputlabel>
                    <apex:outputPanel layout="block" styleClass="requiredInput">
                        <apex:outputPanel layout="block" styleClass="requiredBlock"/>
                        <apex:selectlist value="{!ConvertedStatus}" required="true" multiselect="false" size="1" onchange="processChange()">
                            <apex:selectOptions value="{!ConvertedStatuses}"/>
                        </apex:selectlist>
                    </apex:outputpanel>
                </apex:pageblocksectionitem>

Controller:

    public String QualifyingReason {get; set;}
    public List<SelectOption> QualifyingReasons {get; set;}


What my page looks like:
Visual Force page

Best Answer chosen by TraciKim
Doug Beltowski XDoug Beltowski X
Does your Visualforce page use the Lead standard controller?
<apex:page standardController="Lead" ... >
If so you could use an apex:inputField
<apex:inputField value="{!Lead.Qualifying_Reason__c}" />

If your VF page does not use the standard controller for Lead then you'll probably want to do a "describe (https://developer.salesforce.com/blogs/developer-relations/2008/12/using-the-metadata-api-to-retrieve-picklist-values.html)" on the picklist field.
for(Schema.PicklistEntry pe : Lead.Qualifying_Reason__c.getDescribe().getPicklistValues())
{
	QualifyingReasons.add(new SelectOption(pe.getLabel(), pe.getValue()));
}

 

All Answers

Mahesh DMahesh D
Please follow the below example:


 
<!-- Page: -->
<apex:page controller="sampleCon">
    <apex:form>
        <apex:selectList value="{!countries}" multiselect="true">
            <apex:selectOptions value="{!items}"/>
        </apex:selectList><p/>

        <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
    </apex:form>

    <apex:outputPanel id="out">
        <apex:actionstatus id="status" startText="testing...">
            <apex:facet name="stop">
                <apex:outputPanel>
                    <p>You have selected:</p>
                    <apex:dataList value="{!countries}" var="c">{!c}</apex:dataList>
                </apex:outputPanel>
            </apex:facet>
        </apex:actionstatus>
    </apex:outputPanel>
</apex:page>
            
/*** Controller: ***/
    public class sampleCon {
        String[] countries = new String[]{};
            
        public PageReference test() {
            return null;
        }
            
        public List<SelectOption> getItems() {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('US','US'));
            options.add(new SelectOption('CANADA','Canada'));
            options.add(new SelectOption('MEXICO','Mexico'));
            return options;
        }
            
        public String[] getCountries() {
            return countries;
        }
            
        public void setCountries(String[] countries) {
            this.countries = countries;
        }
    }

Source:

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_selectList.htm

Regards,
Mahesh
Doug Beltowski XDoug Beltowski X
Does your Visualforce page use the Lead standard controller?
<apex:page standardController="Lead" ... >
If so you could use an apex:inputField
<apex:inputField value="{!Lead.Qualifying_Reason__c}" />

If your VF page does not use the standard controller for Lead then you'll probably want to do a "describe (https://developer.salesforce.com/blogs/developer-relations/2008/12/using-the-metadata-api-to-retrieve-picklist-values.html)" on the picklist field.
for(Schema.PicklistEntry pe : Lead.Qualifying_Reason__c.getDescribe().getPicklistValues())
{
	QualifyingReasons.add(new SelectOption(pe.getLabel(), pe.getValue()));
}

 
This was selected as the best answer
TraciKimTraciKim
Thank you Doug! That worked. Should've posted on here earlier today, that would have saved me a lot of grief! Thanks again :)