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

data in the dropdown list

Hi all,


On my Visualforce page, I would like to display the account names in a dropdown list.


For each account record, I have a custom field called display. If that display box is ticked, I would like to display the name of the account in the list. 


Is there a way to do that please? 


Many thanks 



Hello Tin;




public class MyClass{

public List<SelectOption> getAccountList() {

Account[] accounts = [SELECT name FROM Account WHERE display = true];

List<SelectOption> options = new List<SelectOption>();

for (Account acc : accounts) {

options.add(new SelectOption('',acc.Name));


return options;





 VF Page:

<apex:page controller="MyClass">


<apex:selectlist size="1">

<apex:selectoptions value="{!accountList}"></apex:selectoptions>












Many thanks for your reply. The code works beautifully if it is on it's own. If I were to put it in the existing class for existing page, it throws me an error message  on the visualforce page saying accountList unknown.


But I now have an idea.


Much appreciated your reply.





how to get the Account name in the  controller after selecting any one Account in visulforce???

Thanks in Advanve. 


accountList replace with getaccountList in visual force page



How to use the same method to display CONTACT NAME in VF PAGE ?