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
Avinash AAvinash A 

Getting List of Sobjects in the org.

Hi guys,

My requirement is to get a list of all standad and custom object apis in a list.
I dont want to list Objects like RecordType, ApexPage etc.
I want only buesness objects (Such as Account,Contact,Opportunity etc) ,and custom objects if any.
Please Help Me Out.......
RKSalesforceRKSalesforce
Hi Avinash,

You can get it by using Dynamic Apex:
Map<String, Schema.SObjectType> m =  Schema.getGlobalDescribe();
Please let me know if helped.

Regards,
Ramakant
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Avinash,
Please check the below code we should use predefined methods which are provided in schema class and also check the code to retrieve object through SOQL Queries.
 
VisualForce Page:
<apex:page controller="schemademo2" >
  <apex:form >
    <apex:pageBlock >
      <apex:pageBlockSection id="fields" >
         <apex:selectList value="{!selectedobject}" label="Object:::" size="1">
          <apex:selectOptions value="{!objname}"/>
            <apex:actionSupport event="onchange" action="{!searchFields}"/>
         </apex:selectList>
         <apex:pageBlockSectionItem >
            <apex:selectList value="{!selectedfield}" label="Field:::" size="1">
              <apex:selectOptions value="{!fldname}" />
               <apex:actionSupport event="onchange" action="{!searchValues}"/>
            </apex:selectList>
         </apex:pageBlockSectionItem>
         <apex:pageBlockSectionItem >
            <apex:selectList value="{!selectedvalue}" label="Values:::" size="1" id="values" >
              <apex:selectOptions value="{!valname}" />
            </apex:selectList>
         </apex:pageBlockSectionItem>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>  
</apex:page>

Apex:
public class schemademo2 {   
  public string selectedobject{get;set;}
  public List<selectoption> objname{get;set;}
  public string selectedfield{get;set;}
  public List<selectoption> fldname{get;set;}
  public string selectedvalue{get;set;}
  public List<selectoption> valname{get;set;}
  public boolean pb1{get;set;}
  Map<string,schema.sobjectType> mobj = schema.getGlobalDescribe();
public schemademo2(){
  objname = new List<selectoption>();
  Map<string,schema.sobjectType> mobj = schema.getGlobalDescribe();
  List<string> entities = new List<string>(mobj.keyset());
  entities.sort();
  objname.add(new selectoption('---Select Object---','----Select Object---'));  
  for(string f:entities){ 
   if (f.contains('__c')) 
  // if (!f.contains('__c'))  
  objname.add(new selectoption(f,f));
 }
 }
public PageReference searchFields() {
  Map<string,sobjectField> mfld = mobj.get(selectedobject).getDescribe().fields.getMap();
  fldname = new List<selectoption>();
  List<string> fldentities = new List<string>(mfld.keyset());
  pb1=true;
  fldentities.sort();
  fldname.add(new selectoption('---Select Field---','----Select Field---'));
  for(string sf:fldentities){
    fldname.add(new selectoption(sf,sf));
 }
    return null;
}    
   public PageReference searchValues() {
     string dquery = 'select '+selectedfield+' from '+selectedobject;         
     List<Sobject> vals = Database.query(dquery);
     valname= new List<selectoption>();
           for(sobject val:vals){
      if(val.get(selectedfield)!=null)
       valname.add(new selectoption(string.valueof(val.get(selectedfield)),string.valueof(val.get(selectedfield))));
       } 
       return null;
       }
       }

hope it will be helpful.

Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.

Best Regards
Rahul Kumar
 
 
Baz DensonBaz Denson
If you don't need to do it programatically, there are a couple of tools I use. 

sftoolkit.co has a number of useful tools.

https://organizer.enree.co/index.html is a chrome extension that does an org describe amongst other features
Avinash AAvinash A
Hi @Rahul Kumar,

The code which you have provided will give only  custom objects.My requirement is to also get standard business objects( like account, lead , contact) and to avoid objects like(profiles,record types etc)