[SalesForce] How to list down all Standard/Custom Objects and ignore System(Internal) Objects

There's always a requirement to pull ALL standard and custom objects using describe call ignoring all system/internal objects. Is there a way for same?

One of option is to reference ProcessInstance object (ie ApprovalProcess enabled objects)

for(Schema.SObjectType item : ProcessInstance.TargetObjectId.getDescribe().getReferenceTo()) { ..} 

I was successfully using this approach in my appexchange app code, however these lines don't work (are not supported) in PE org as PE doesn't support approval process by default.

I have been through this post How to find only those Schema.SObjectType types that are visible in the Schema Builder but that too doesn't have a definite/100% solution to list down (almost) ALL standard and custom objects (and ignore system objects)? I think Andrew's response does help to certain level.

Any work around to fetch ALL standard and custom objects (and ignore system/internal objects)?

UPDATE (11 Dec, 14) Posted an Idea on IdeaExchange. Please Vote
Idea Add isSystemObject() in GetDescribe to indicate if an object is
System/Internal

Best Answer

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();
}
Related Topic