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
tulasiram chtulasiram ch 

How to get List Of All Standard Objects...i used following code, code is working but debug not printing the object names...

public class standardObjectsNames{
public void standardObjectsNames(){
    List<string> stdObjects = new List<string>();
    for(Schema.SObjectType type:Schema.getGlobalDescribe().Values()){
    string Objnames=string.valueOf(type);
    if(!Objnames.contains('__c')){
    stdObjects.add(Objnames);
}
}
System.debug('Sobjects in my org :' +stdObjects);

}
}
sfdc  novicesfdc novice
Hi Tulasiram,

Please use this Code, this will display all Standard Objects.
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() ){
     
          if(!s.contains('__')){
     
             objlist.add( new selectoption(s,s));
             
          }    
         
     }
     
     system.debug('================' + objlist);
     
     return objlist;
     
    }

}

Thanks.
tulasiram chtulasiram ch
Hi Sfdc_noVoice Code is ok , but debug log not showing any printed listUser-added image
Amit Chaudhary 8Amit Chaudhary 8
Please check below post to see all object and field
1) http://amitsalesforce.blogspot.com/2015/11/apex-describe-dynamic-retrieval-of.html

Please try below code and try to debug
Map<string,Schema.sObjectType> AllObjMap = new Map<string,Schema.sObjectType>();
 AllObjMap = Schema.getGlobalDescribe();
for(string s : AllObjMap.keyset() ){
if(!s.contains('__')){
  System.debug('------------>S'+s);
}
}

User-added image


IF you want to see on VF page try below code
public with sharing class DescibeDemoController 
{
    public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    public String selectedObject {get; set;}
    public List<FieldWrapper> listField{get;set;}

    public DescibeDemoController() 
    {
        listField = new List<FieldWrapper>();
    }

    // find all sObjects available in the organization
    public  List<SelectOption> getListObejectName() 
    {
        List<SelectOption> objNames = new List<SelectOption>();
        List<String> entities = new List<String>(schemaMap.keySet());
        entities.sort();
        for(String name : entities)
		{
			if( !name.contains('__') )
			{
				objNames.add(new SelectOption(name,name));
			}	
		}	
        return objNames;
    }

    
    // Find the fields for the selected object
    public void showFields() 
    {
        listField.clear();
        Map <String, Schema.SObjectField> fieldMap = schemaMap.get(selectedObject).getDescribe().fields.getMap();
        for(Schema.SObjectField sfield : fieldMap.Values())
        {
            schema.describefieldresult dfield = sfield.getDescribe();
            FieldWrapper wObj = new FieldWrapper();
            wObj.fieldName = dfield.getLabel ();
            wObj.fieldAPIName = dfield.getname();
            listField.add(wObj);
        }
    }

    public class FieldWrapper
    {
        public String fieldName {get; set;}
        public String fieldAPIName {get; set;}
    }

}
VF page
<apex:page controller="DescibeDemoController">
    <apex:form id="Describe">
        <apex:pageBlock id="block2" >
            <apex:pageblockbuttons location="top" >
                    <apex:commandButton value="Show Fields" action="{!showFields}" />
            </apex:pageblockbuttons>
            
            <apex:pageblocksection >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Object Name</apex:outputLabel>
                    <apex:selectList value="{!selectedObject}" size="1">
                        <apex:selectOptions value="{!ListObejectName}"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
            </apex:pageblocksection>
        </apex:pageBlock>
        
        <apex:pageBlock id="result" title="Field Detail for {!selectedObject}" rendered="{!if(listField.size > 0 ,true,false)}"   >
            <apex:pageBlockTable value="{!listField}" var="field" rendered="{!if(listField.size > 0 ,true,false)}"> 
                <apex:column value="{!field.fieldName }" headerValue="Name" />
                <apex:column value="{!field.fieldAPIName }"  headerValue="API Name"/>
            </apex:pageblockTable>
        </apex:pageblock>
    </apex:form>
</apex:page>


Let us know if this will help you
 
Sukanya BanekarSukanya Banekar
Hi Tulasiram,
Try with following code,
 
list<string> lstObj= new list<string>();
map<string,Schema.sobjectType> mapObject= Schema.getGlobalDescribe();
for(string objName: mapObject.keySet()){
	lstObj.add(objName);
}
lstObj.sort();
system.debug('lstObj--'+lstObj);


Thanks,
Sukanya Banekar