get all objects in salesforce org

In order to get all the object names in your org, use Schema.getGlobalDescribe() method. This would return a map of object names and object types. Keyset would be all the object names. Following visualforce page uses this method to display all the objects in an org.


Visualforce page
<apex:page controller="AllObjectsinOrg">
 <apex:form >
   <apex:pageBlock id="pgblck">
    <apex:outputlabel value="Object Name" for="ObjPickList"/>      
    <apex:selectList value="{!ObjectSelected}" multiselect="false" id="ObjPickList" size="1">
       <apex:selectOptions value="{!ObjList}"/>
    </apex:selectList>
 </apex:pageBlock>
 </apex:form>
</apex:page>

Controller
public class AllObjectsinOrg {
 Public string ObjectSelected{get;set;}
 Public Map<String, Schema.SObjectType> AllObjmap;
 Public AllObjectsinOrg(){
    AllObjmap = New Map<String, Schema.SObjectType>();
    AllObjmap = Schema.getGlobalDescribe();
    System.debug('******All object Names :'+ AllObjmap.keyset());
}
Public List<selectoption> getObjList(){
    List<selectoption> objList = new List<selectoption>();
    for(string s:AllObjmap.keyset()){
        objList.add(new selectoption(s,s));
    }
  return objList;   
 }
}

2 comments:

  1. Hi Yoganand,

    I am getting this error:
    Visualforce Error

    Collection size 1,926 exceeds maximum size of 1,000.

    how should i proceed?

    ReplyDelete
  2. i only want those objects whose records can be created for example Apex Trigger I dont want in my list How can i do this can somebody help me?

    ReplyDelete