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
rangaranga 

List of all the objects in the org.

Hi everyone,

Is there a way to get an list of all the objects in the development org.? I have tried using a schema method as below,

 

Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();

 

But I can only obtain a Map of sObjectType.

 

Thanks. 

 

Best Answer chosen by Admin (Salesforce Developers) 
rangaranga

Thank you very much Ankit,

I think, I havent asked the question properly. What I actually needed was a Map of sObject s. :) 

But I went through your blog and came up with an answer. I will post that for the sake of competion of this thread.

 

public Map<String,sObject> getSobjects()

{

        Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();

        Map<String, sObject> sObjects=new Map<String,sObject>();

        Set<String> keys=new Set<String>();

        keys=gd.keySet();

        for(String key:keys)

{

            sObject sObj = Schema.getGlobalDescribe().get(key).newSObject() ;

            sObjects.put(key,sObj);

        }

        return sObjects;

     }

 

Thanks again Ankit.

All Answers

Ankit AroraAnkit Arora

Here is the code :

 

Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
Set<String> objectKeys = gd.keySet();
for(String objName : objectKeys)
{
      System.debug('Object Names :::: ' + objName) ;
}

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

rangaranga

Thank you very much Ankit,

I think, I havent asked the question properly. What I actually needed was a Map of sObject s. :) 

But I went through your blog and came up with an answer. I will post that for the sake of competion of this thread.

 

public Map<String,sObject> getSobjects()

{

        Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();

        Map<String, sObject> sObjects=new Map<String,sObject>();

        Set<String> keys=new Set<String>();

        keys=gd.keySet();

        for(String key:keys)

{

            sObject sObj = Schema.getGlobalDescribe().get(key).newSObject() ;

            sObjects.put(key,sObj);

        }

        return sObjects;

     }

 

Thanks again Ankit.

This was selected as the best answer