Though not 100% an answer, but based on various posts and comments (like one from @Andrew), below is solution which will give you list of all standard and custom objects ignoring system objects:
public List < SelectOption > getStandardCustomIgnoreSytemObjects() {
List < SelectOption > options = new List < SelectOption > ();
for (Schema.SObjectType item1: Schema.getGlobalDescribe().values()) {
String name = item1.getDescribe().getName();
// Exclude all the unwanted Sobjects e.g. CustomSettings, History, Share, Feed, ApexClass, Pages etc..
if (!item1.getDescribe().isCustomSetting() && item1.getDescribe().getRecordTypeInfos().size() > 0 && item1.getDescribe().isCreateable() &&
!name.containsignorecase('history') && !name.containsignorecase('tag') && !name.containsignorecase('share') && !name.containsignorecase('feed')) {
options.add(new SelectOption(item1.getDescribe().getName(), item1.getDescribe().getLabel()));
}
}
options.add(new SelectOption('Asset', 'Asset')); // Asset doesn't come-up, so explicitly add same.
options.sort();
}
To get the list of all objects in your org, you can use something like this:
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
for(Schema.SObjectType thisObj : gd.values()) {
System.debug(thisObj);
}
Run that in the Developer Console and you will see a long list of Object names:
Note this includes every object in your schema, including Custom objects and even things like Knowledge article types and field_history tracking objects...
To put that into a picklist, in the Apex controller of your Visualforce page, instead of System.debug
- build a list of Options:
public List<SelectOption> getObjectOptions(){
List<SelectOption> options = new List<SelectOption>();
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
for(Schema.SObjectType thisObj : gd.values()) {
options.add(new SelectOption(thisObj, thisObj));
}
return options;
}
and on your page:
<apex:selectList >
<apex:selectOptions value="{!options}"/>
</apex:selectList>
Now you have a picklist of all your options.
Use actionFunction
to run an "onclick" on that, or perhaps just some javascript, or a normal apex:button
to submit the value back to the controller, and then use Schema
again to get all the related lists for that object:
Map<string,string> childMap = new Map<String, String>();
List<Schema.Childrelationship> childList = Schema.getGlobalDescribe().get(selectedOption).getdescribe().getChildRelationships();
(where selectedOption
is what was picked in the picklist).
Now you have a List of all the related object names! Use it as you will
(and don't forget test coverage!)
Best Answer
You surely can using
Schema.getGlobalDescribe()
, as mentioned in the comments. It returns aMap<String, SObjectType>
, so you can get aSet<String> objectNames
or aList<SObjectType>
quite easily from it, among other uses. For instance, you could easily use it to generate aList<SelectOption>
for use in a classicVisualforce Page
: