+ Start a Discussion
pranav shah 40pranav shah 40 

Select option list

Hi All,
Below is my apex class and Vf page, to display list of all Sobjects in My org.. Now Suppose, If i select Account from Dropdown, i need to display all the list of all the account name in my org... how it will be done

public class ObjectList
{
public String Value{get;set;}
public List<SelectOption> getName()
{
List<Schema.SObjectType> gd= Schema.getGlobalDescribe().values();
List<SelectOption> options = new List<SelectOption>();
for (Schema.sobjecttype b: gd)
{
options.add(new SelectOption(b.getdescribe().getlabel(),b.getdescribe().getlabel()));
options.sort();

}
return options;
}
}


VF page:

<apex:page controller="ObjectList"> <apex:pageBlock title="ObjectList"> <apex:form id="pageload"> <apex:pageBlockSection > <apex:selectList value="{!Value}" size="1"> <apex:selectOptions value="{!Name}"> </apex:selectOptions> </apex:selectlist> </apex:pageblocksection> </apex:form> </apex:pageBlock> </apex:page>
Zhen Yueh LeanZhen Yueh Lean
Hi Pranav,

You can try to add the onChange event on selectList to call a apex function which will invoke a method in your controller. The method will need to query all accounts and populate the name into a new List<SelectOption>. This new list will be used by a 2nd selectList in your vf page. Then you should rerender the 2nd selectList.

Please note that salesforce only allows you to query max 50K records in one runtime.