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
Alex Miller 93Alex Miller 93 

Get all Objects Names

I'm trying to write a program to pull in all the objects our admins regularly modify. These don't include system objects such as Approvals and Opportunitycontactrole. The list I'm wanting to pull is the one you find by going to Setup->Create->Objects. 

User-added image

I have this code. The problem with this code takes too long to iterate. I keep getting a CPU timeout error in the Dev console. I noticed it is pulling things like Approvals. I'm only interested in the custom object screen plus standard objects like Accounts, Contacts, Opportunities, and so on. Not the System Standard objects.
for(Schema.SObjectType objTyp : Schema.getGlobalDescribe().Values()){
    system.debug('****-->'+ objTyp.getDescribe().getLabel());
}
Anyone know how to pull that without generating a manual custom setting list?
 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Alex,

Greetings to you!

You can get the list from the following SOQL:
 
SELECT SObjectType FROM ObjectPermissions GROUP BY SObjectType ORDER BY SObjectType ASC

Also, you can use below code:
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); 
Set<String> standardObjects = new Set<String>();
Set<String> customObjects = new Set<String>();
for(Schema.SObjectType d : gd.values())
{
    Schema.DescribeSObjectResult ds = d.getDescribe();
    if(!ds.isCreateable())
      continue;
    if(ds.isCustom() == false && ds.getRecordTypeInfos().size() > 0)
        standardObjects.add(ds.getName());
    else if(ds.isCustom())
        customObjects.add(ds.getName());
}
List<String> sortedNames = new List<String>(customObjects);
sortedNames.sort();
for(String name : sortedNames)
  System.debug('Custom object: ' + name);
sortedNames = new List<String>(standardObjects);
sortedNames.sort();
for(String name : sortedNames)
  System.debug('Standard object: ' + name);

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Raj VakatiRaj Vakati

You can able to do it by using REST APi and Apex schema namespace

REst API 

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_describeGlobal.htm


 

List < Schema.SObjectType > gd = Schema.getGlobalDescribe().Values();      
Map<String , Schema.SObjectType > globalDescription = Schema.getGlobalDescribe();   
        
for ( Schema.SObjectType f : gd ) {  
  
    Schema.sObjectType objType = globalDescription.get(f.getDescribe().getName() );  
    Schema.DescribeSObjectResult r1 = objType.getDescribe();   
    Map<String , Schema.SObjectField > mapFieldList = r1.fields.getMap();    
  
    for ( Schema.SObjectField field : mapFieldList.values() ) {    
      
        Schema.DescribeFieldResult fieldResult = field.getDescribe();    
  
        if ( fieldResult.isAccessible() ) {    
          
            System.debug('Field Name is ' + objType + '.' + fieldResult.getName() );  
              
        }   
          
    }  
      
}
 

Refer this links


https://jungleeforce.wordpress.com/2013/06/07/extracting-list-of-all-the-objects-standard-custom-in-salesforce/
https://salesforce.stackexchange.com/questions/48920/dynamic-picklists-of-objects-its-fields/48936#48936
https://salesforce.stackexchange.com/questions/100668/retrieve-api-names-of-all-object-in-salesforce-org-using-soql
https://developer.secure.force.com/cookbook/recipe/retrieve-a-list-of-objects-using-apex
http://www.infallibletechie.com/2015/08/how-to-get-all-field-names-in-all.html

raju petluriraju petluri
Hi Alex Miller 93

Try this.
SELECT Label, QualifiedApiName FROM EntityDefinition