We can use Schema.getGlobalDescribe()
to get all properties of sObject
.
Apex Class:
public class SampleController { Public string selectedObj{get;set;} Public List<Selectoption> getObjList(){ List<Schema.SObjectType> objList = Schema.getGlobalDescribe().Values(); List<SelectOption> objNames = new List<SelectOption>(); objNames.add(new SelectOption('','-- Select --')); for(Schema.SObjectType obj : objList) { objNames.add(new SelectOption(obj.getDescribe().getName(),obj.getDescribe().getLabel())); } objNames.sort(); return objNames; } }
Visualforce Page:
<apex:page controller="SampleController"> <apex:form > <apex:pageBlock> <apex:outputlabel value="Object Name" for="plObj"/> <apex:selectList value="{!selectedObj}" multiselect="false" id="plObj" size="1"> <apex:selectOptions value="{!ObjList}"/> </apex:selectList> </apex:pageBlock> </apex:form> </apex:page>