+ Start a Discussion

Problem in adding all account names in picklist

Hi SFDC Developers,


I have one VF page and it contains a one picklist.SO now i want to append all account names in this picklist.so how i can achiev this task?


Thanks & regards,

SFDC Fun...!!!

Rahul AgarwalRahul Agarwal



You will have to create a custom picklist to do that. Fetch all the picklist values using describe call and then fetch all the account names. Run your logic to forrm new picklist values and store them in a list<string>. After this use <apex:selectList> to form the custom picklist and display it on your VF Page.



Groundwire ConsultingGroundwire Consulting



Go through below code



public with sharing class picklistcls4 {

public List<selectoption> items { get; set; }

public String selected { get; set; }

public picklistcls4(){

     items=new List<selectoption>();

        items.add(new selectoption('','--Select an lead--'));

        List<lead> lstl= [select id,name from lead];

        for(lead a:lstl){

             items.add(new selectoption(a.id,a.name));




VF Page:


<apex:page controller="picklistcls4">

<apex:form >

<apex:pageBlock >

<apex:selectList value="{!selected}" size="1" onchange="getitem()">

<apex:selectOptions value="{!items}"/>







and if you have any more questions please feel to contact me on support@groundwireconsulting.com


Thankyou very much.