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
pooja biswaspooja biswas 

bind sobjects to picklist

HI friends
I have a requirement where I need to bind sobjects to an picklist and show it in visual force page.
Can it be done using dynamic apex ?
pls let me know.

pooja
 
Best Answer chosen by pooja biswas
Srinivas SSrinivas S
Hi Pooja,

Please find the following solution which is tested -
Controller Class:
public class AllObjectsInPicklist {
    public List<SelectOption> getObjects() {
        List<SelectOption> options = new List<SelectOption>();
        for(Schema.SObjectType objTyp : Schema.getGlobalDescribe().Values()){
            options.add(new SelectOption(objTyp.getDescribe().getLabel(),objTyp.getDescribe().getName()));
        }
        return options;
    }
}
Visualforce Page:
<apex:page controller="AllObjectsInPicklist" tabStyle="Account">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection title="Objects Selection" collapsible="false">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="object Type"/>
                    <apex:selectList size="1">
                        <apex:selectOptions value="{!objects}"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Result:
User-added image

------------
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.