8

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

  • You may want to get the Edition type and then do a conditional on your schema call. That would at least allow you to continue to use what you know works in all Editions except PE Editions. You could then work out something more convoluted to get what you need for Professional Edition Orgs. – crmprogdev Nov 26 '14 at 15:15
  • Thank you @crmprogdev! I'm following what you suggested, adding conditional logic to check Edition type and accordingly work out for time-being. However, waiting for definite answer here as this seems to be problem/request from many AppExchange app creators. – Chirag Mehta Nov 27 '14 at 3:46
  • I've just taken a fresh look at the Apex Describe API and cannot see any way to improve my original answer on the other post, sorry i cannot add an answer to this one other than to reference my previous one. – Andrew Fawcett Dec 11 '14 at 10:01
  • 1
    @AndrewFawcett Ok, thank you for reviewing this. It's sad that no such attribute available as of now. Posted idea @ success.salesforce.com/ideaView?id=08730000000DhFJAA0 (Please vote). Thanks! – Chirag Mehta Dec 11 '14 at 13:27
  • @AndrewFawcett Posted an answer, please review - salesforce.stackexchange.com/questions/57259/… – Chirag Mehta Dec 12 '14 at 16:30
4

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();
}
  • salesforce is adding many system objects by every release, so i would come again in the list once new release happen. Any other workaround for this? – Jenish Shingala Jul 27 '15 at 8:55
1

You can get the list from the following SOQL:

SELECT SObjectType From ObjectPermissions Group By SObjectType

This basically gets you all objects for which you can assign permissions in a Profile.

  • Child Objects (Master-Detail relationship) ones will not be listed in ObjectPermissions, right ? – Chirag Mehta Sep 9 '16 at 7:20
  • All object are listed @ChiragMehta, including Child Objects (Master-Detail relationship) – Vishal Shah Sep 10 '16 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.