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
Anuj.ShuklaAnuj.Shukla 

List of objects and list of fields of an object

Hi All,

 

I have following requirements:

 

>>I have to show a dropdown which should list all the custom objects as well as all the customizable standard objects (non customizable objects should be excluded).

 

>>I also need to write a method which would return me list of fields for the object name I pass to this method.

 

Can somebody help me with these two solutions?

 

 

Thanks,

Anuj

 

Imran MohammedImran Mohammed

To get all objects in an org, 

Map<String, Schema.SobjectType> allObjects = Schema.getGlobalDescribe();

 

To get fields of a particular object,

for(Schema.SobjectType sObjectSelected: allObjects.values())

{

         Schema.DescribeSObjectResult objectResult = sObjectSelected.getDescribe() ;

 

         Map<String, Schema.SObjectField> fieldMap = objectResult.fields.getMap();//This will give list of fields of a particular object
}