9

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

5
  • 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
    Commented Nov 26, 2014 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. Commented Nov 27, 2014 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. Commented Dec 11, 2014 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! Commented Dec 11, 2014 at 13:27
  • @AndrewFawcett Posted an answer, please review - salesforce.stackexchange.com/questions/57259/… Commented Dec 12, 2014 at 16:30

2 Answers 2

5

Though not 100% an answer, but based on various posts and comments (like one from @Andrew), below is a solution which will give you a 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 the same.
  options.sort();
}
1
  • 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? Commented Jul 27, 2015 at 8:55
3

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.

4
  • Child Objects (Master-Detail relationship) ones will not be listed in ObjectPermissions, right ? Commented Sep 9, 2016 at 7:20
  • All object are listed @ChiragMehta, including Child Objects (Master-Detail relationship) Commented Sep 10, 2016 at 12:07
  • This is a great idea!
    – codeulike
    Commented Apr 21, 2021 at 14:26
  • This will miss custom metadata records
    – Amit Singh
    Commented Sep 21, 2021 at 6:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .