1

We have need to run through every object in an org to determine which ones have certain fields our app needs. We ONLY care about the actual objects (case, campaign, contract, custom objects, etc...). But doing a global describe on objects returns CampaignShare, CampaignFeed, etc...

I noticed four suffixes: *Share, *Feed, *History, *ChangeEvent

I want to skip these entirely as it just adds to execution time for our loop. Is there anyway to determine if an object is an object that actually shows up in the Objects tab in an org, and not its share, feed, history, or changeevent? Or is the only option for this to check if its name ends with one of these suffixes?

2

The closest you can get is to check isSearchable(); this should return true only for top-level objects (e.g. Account or Contact) but not meta-children (e.g. AccountShare or ContactShare).

SObjectType[] types = new SObjectType[0];
for(SObjectType sType: Schema.getGlobalDescribe().values()) {
  if(sType.getDescribe().isSearchable()) {
    types.add(sType);
  }
}

This should be relatively future-proof.

1
  • Thanks, this worked great and cleaned up my list of objects! Aug 1 '19 at 18:39
2

I don't know if this also helps, but I once asked in the Apex Metadata API community about what are the valid Entity Definitions that a Custom Metadata field can look up to, and Vladimir Gerasimov told me:

It's not very straightforward but in general the entity has to be: a) Triggerable b) Customizable c) Layoutable d) Queryable e) And not 'User', 'Task', 'Event' or 'Holiday'

You can probably check it using SOQL like: SELECT FROM EntityDefinition WHERE IsTriggerable = true AND isCustomizable = true AND IsLayoutable = true AND IsQueryable = true AND QualifiedApiName NOT IN ('User', 'Task', 'Event', 'Holiday')

Perhaps this too could be of help in narrowing down the "first-class objects".

1
  • sfdcfox's solution is enough for my situation, and avoids an extra query. But this query is good to know for potential future use. Thank you for providing it. Aug 1 '19 at 18:40

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.