How to get list of objects used in an organization using apex in Salesforce?

Sample code:
//Just to display, use the below code. public class ImportCtrlr 
    public Map<String, Schema.SObjectType> objs {get; set;}

public ImportCtrlr()
objs = Schema.getGlobalDescribe();

For manipulation with list of objects:

Visualforce page:

    <apex:page controller="objectList" >     
    <apex:form >
        <apex:SelectList value="{!name}" size="1">
            <apex:selectOptions value="{!names}"></apex:selectOptions>

Apex Controller:

    public class objectList
      public String name {get;set;}
      public List<SelectOption> getNames()
          List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();   
          List<SelectOption> options = new List<SelectOption>();
          for(Schema.SObjectType f : gd)
             options.add(new SelectOption(f.getDescribe().getName(),f.getDescribe().getName()));
          return options;


No comments:

Post a Comment

Sharing is Caring!!! Share this with your friends!!!

submit to reddit