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 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.

Apex:

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' + ' -');
        pickList.add(firstOption);
        for MyObject__c mpgObj : mpgList) {
                this.pickList.add(new SelectOption(mpgObj.id,string.valueOf(mpgObj.Price__c)));
        }
}

Visualforce page:

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

OutPut : Image

share|improve this question
1  
I can't see an error description? What is wrong with that picklist? –  mast0r May 26 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 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 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 at 8:28

2 Answers 2

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" –  mast0r May 26 at 8:35
    
Mayby... But I don't think it will be required. –  Artur Kępczyński May 26 at 8:45
    
Yes multiselect="false" isn't required as it has picklist datatype not multi Picklist datatype. –  SFDC Geek May 26 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}"/>
</apex:selectList> 
share|improve this answer

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.