Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to show a custom dropdown list. I have built some code, but output isn't coming as expected. I have added the output screenshot in the attachment.

Requiremnt : 2 Custom Object : MyObject__c (Fields:MPG_Code__c, Price__c) and MyObject_Config__c(Fields : MPG_Code__c). Both objects share a common field(MPG_Code__c)

My requirement is to show all price__c of MyObject__c available for that MPG_code__c in a dropdown.


public class PriceGroupConfigControllerExt {

    public final MyObject_Config__c myObj {get; private set;} 
    ApexPages.StandardController stdController;
    public list<SelectOption> pickList {get; private set;}
    public String selectedId {get; set;}

public PriceGroupConfigControllerExt(ApexPages.StandardController Controller) {  

        stdController = Controller;                
        this.myObj = (MyObject_Config__c)stdController.getRecord(); 

    List<MyObject__c> mpgList = [Select Id, MPG_Code__c,Price__c                                
                                 From MyObject__c 
                                 Where MPG_Code__c =: myObj.MPG_Code__c 

    if (pickList == null) {
            pickList = new list<SelectOption>();

        SelectOption firstOption = new SelectOption('', ' - Select Discount price' + ' -');
        for MyObject__c mpgObj : mpgList) {
                this.pickList.add(new SelectOption(,string.valueOf(mpgObj.Price__c)));

Visualforce page:

<apex:outputLabel>Specific Discount</apex:outputLabel>
   <apex:selectList id="discountPrice" value="{!selectedId}" >
<apex:selectOptions value="{!pickList}"/>

OutPut : Image

share|improve this question
I can't see an error description? What is wrong with that picklist? – Sergey Utko May 26 '14 at 8:16
In the actual code have you changed mpgcObj to myObj? The code you have posted doesn't look like it would compile. – Keith C May 26 '14 at 8:18
@mast0r : All the values of Picklist should come as a dropdown. But Here all the values are coming differently. In the image I have posted the output. – SFDC Geek May 26 '14 at 8:27
@KeithC : Yes In the actual code I have changed the code to myObj. It was a typing mistake. Still same error is coming – SFDC Geek May 26 '14 at 8:28
up vote 3 down vote accepted

I think you need add one more paramether to your list. Try size="1" in your apex:selectList

share|improve this answer
And maybe multiselect="false" – Sergey Utko May 26 '14 at 8:35
Mayby... But I don't think it will be required. – Artur Kępczyński May 26 '14 at 8:45
Yes multiselect="false" isn't required as it has picklist datatype not multi Picklist datatype. – SFDC Geek May 26 '14 at 8:51

Thanks to @Artur. Here is the solution. We only have to add Size='1'

<apex:selectList id="discountPrice" value="{!selectedId}" size="1" >
   <apex:selectOptions value="{!pickList}"/>
share|improve this answer

Your Answer


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.