Tuesday, 12 April 2016

List Of Custom objects using schema


public  class SchemaExample2 {
     public Map<String,Schema.SobjectType> objects {set;get;}
     public List<SelectOption> options {set;get;}
     public List<String> objNames{set;get;}
     public String selected {set;get;}
     public String describe {Set;get;}
     public SchemaExample2(){
          objects=Schema.getGlobalDescribe();
          options=new List<selectOption>();
          objNames=new List<String>();
          Set<String> keys=objects.keySet();
          objNames.addAll(keys);
          objNames.sort();
          for(String s:objNames){
              Schema.DescribeSobjectResult result=objects.get(s).getDescribe();
              if(result.isCustom()){
                   SelectOption op=new SelectOption(s,s);
                   options.add(op);
              }
          }
     }
     public void getDetails(){
          Schema.DescribeSobjectResult result=objects.get(selected).getDescribe();
          describe=''+result;
     }
    
}
Visualforce Page
<apex:page  controller="SchemaExample2">
     <apex:form>
          <apex:panelGrid columns="3" id="one">
              <apex:selectList value="{!selected}" size="1">
                   <apex:selectOptions value="{!options}" />
     <apex:actionSupport event="onchange"  action="{!getDetails}" reRender="one" />
              </apex:selectList>
              <apex:commandButton value="GetProperties" action="{!getDetails}" />
              <apex:inputTextArea value="{!describe}" rows="5" cols="70" />
          </apex:panelGrid>
     </apex:form>

</apex:page>

No comments:

Post a Comment