You need to sign in to do that
Don't have an account?
smita bhargava
repeated picklist values
I have a code where I am binding account object , Type field values to an custom picklist in visualforce page.
when I run the code many of the picklist values are repeated.
Picklist values 'Prospect' is repeated two times , 'Customer-Direct" is repeated 3 times in the picklist.
please let me know the issue.
smita
when I run the code many of the picklist values are repeated.
public class BindPicklistValues { public String strSelected{get;set;} public List<SelectOption> options{get;set;} public List<SelectOption> getValues() { strSelected=''; options=new List<SelectOption>(); options.add(new selectOption('', '- None -')); for(Account a:[select ID,Type from Account]) { if (a != NULL) { system.debug('value of a='+a); options.add(new SelectOption(a.ID,a.Type)); } } return options; } } <apex:page controller="BindPicklistValues"> <apex:form > <apex:selectList value="{!strSelected}" multiselect="false" size="1"> <apex:selectOptions value="{!Values}"/> </apex:selectList> </apex:form> </apex:page>
Picklist values 'Prospect' is repeated two times , 'Customer-Direct" is repeated 3 times in the picklist.
please let me know the issue.
smita
Smita- See line 15 where you are querying all the account and adding the type field in the option that is the reason you are getting repeated picklist values from all the account...
If you need to limit to one picklist value then try to use this query If you are working on specific record you may try this class..
Please mark this as the best answer!