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
SPrashantSPrashant 

Creating PickList of All Objects in the Org

Hi,

 

I am having a requirement to create a PIckList  of All the Objects (Custom , Standard) in the org.

This picklist will be part of a Visualforce page which will only be accessible by Admin.

The picklist options will have API names of the Objects as the Value and Object name as Label

 

that is

options.add(new SelectOption(<API Name of the Object>, <Object Label>));

 

Any help is highly appreciated. Thanks in advance.

FromCRMWonderlandFromCRMWonderland
You can use "custom settings" to store info of all "available" objects in the system along with their "Name" & "API name". Whenever new object is created, custom settings should be updated manually accordingly. --- alok
SPrashantSPrashant

Thanks Alok,

 

The answer you suggested is a feasiable.but my problem statement does not permit Custom Setting approach ! :smileyindifferent:

 

Need some dynamic solution related to Org Metadata so that any change done to objects is automatically reflected. I mean to say is there any apex code to fetch all the Object Name and label to put it in SelectOption List  ????

kamlesh_chauhankamlesh_chauhan

Hi Prashant,

 

Here is the sample code. Let me know if you have any difficulties to implement the same.

 

 

public class All_Object{
    Public List<SelectOption> getAllObjectList() {
        Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
        List<Schema.SObjectType> objectList = gd.Values();
        
        String TestName = '';

        List<SelectOption> lstObject = new List<SelectOption>();

        for (Schema.SObjectType s: objectList) {
            string Label = s.getDescribe().getLabel();
            string Name = s.getDescribe().getName();
            
            lstObject.add(new SelectOption(Name,Label));
            
        }
        
        return lstObject;
    }
}

 

 

Regards,

Kamlesh