Skip to main content
pooja biswas perguntou em #Apex
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

 
1 resposta
  1. 10 de mai. de 2016, 12:30
    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:

    Hi Pooja,Please find the following solution which is tested -Controller Class:public class AllObjectsInPicklist { public List<SelectOption> getObjects() { List<SelectOption> options = new List<SelectO

    ------------

    Thanks,

    Srinivas

    - Please mark as solution if your problem is resolved.
0/9000