6

I can find a map of all String -> Schema.SObjectType types by invoking Schema.getGlobalDescribe().

However, that includes a lot of object types I'm not interested in (like casecomment, processinstance or apexlog)

How can I find only those that are available in the Schema Builder?

8

In short after taking a deeper looker at this for you, I have to conclude the answer to your question is that you can only be partially successful in emulating the filters used by Schema Builder...

enter image description here

enter image description here

enter image description here

The isCustom method will help with the first obviously, the second two are harder to separate. The following uses the fact that Schema Builder seems to favour objects with Record Types (via getRecordTypeInfos). So I based further filtering on this. Note that this is governed method so some filtering on isCreateable objects was also needed. Thus some accessible (but not createable objects) are eliminated sadly.

Anyway, since I spent some time on this for you, I thought I would share anyway. Hopefully this gives you some thoughts and if nothing else a conclusion you can move forward with some other approach or variation on this on. Enjoy!

Following is the best I think you will achieve to cover Custom vs Standard.

Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); 
Set<String> standardObjects = new Set<String>();
Set<String> customObjects = new Set<String>();
for(Schema.SObjectType d : gd.values())
{
    Schema.DescribeSObjectResult ds = d.getDescribe();
    if(!ds.isCreateable())
      continue;
    if(ds.isCustom() == false && ds.getRecordTypeInfos().size() > 0)
        standardObjects.add(ds.getName());
    else if(ds.isCustom())
        customObjects.add(ds.getName());
}
List<String> sortedNames = new List<String>(customObjects);
sortedNames.sort();
for(String name : sortedNames)
  System.debug('Custom object: ' + name);
sortedNames = new List<String>(standardObjects);
sortedNames.sort();
for(String name : sortedNames)
  System.debug('Standard object: ' + name);

This results in the following, which gets pretty close, but no cigar....

01:53:17.135 (135755000)|USER_DEBUG|[21]|DEBUG|Standard object: Account

01:53:17.135 (135835000)|USER_DEBUG|[21]|DEBUG|Standard object: Campaign

01:53:17.135 (135903000)|USER_DEBUG|[21]|DEBUG|Standard object: CampaignMember

01:53:17.135 (135972000)|USER_DEBUG|[21]|DEBUG|Standard object: Case

01:53:17.136 (136045000)|USER_DEBUG|[21]|DEBUG|Standard object: Contact

01:53:17.136 (136117000)|USER_DEBUG|[21]|DEBUG|Standard object: ContentVersion

01:53:17.136 (136188000)|USER_DEBUG|[21]|DEBUG|Standard object: Contract

01:53:17.136 (136259000)|USER_DEBUG|[21]|DEBUG|Standard object: Event

01:53:17.136 (136326000)|USER_DEBUG|[21]|DEBUG|Standard object: Idea

01:53:17.136 (136393000)|USER_DEBUG|[21]|DEBUG|Standard object: Lead

01:53:17.136 (136465000)|USER_DEBUG|[21]|DEBUG|Standard object: Opportunity

01:53:17.136 (136534000)|USER_DEBUG|[21]|DEBUG|Standard object: Product2

01:53:17.136 (136601000)|USER_DEBUG|[21]|DEBUG|Standard object: Solution

01:53:17.136 (136668000)|USER_DEBUG|[21]|DEBUG|Standard object: Task

enter image description here

0

What I first used is to check for objects that have a Name field.

Using that you will get the objects that also appear in the Schema Builder and (from what I can see) not the objects that we're not interested in.

However, that will result in too many Object describes , so that won't really work. (edit: describe limits have been lifted since Summer14, so this will work!)

I ended up using

sObjectType == 'Account' || sObjectType == 'Lead' || sObjectType == 'Opportunity' || sObjectType == 'Contact' || schema.getDescribe().isCustom()
0

Please have a look at https://salesforce.stackexchange.com/a/59925/352 (solution to list all standard and custom objects ignoring system objects)

-1

There are a number of methods that can be used to limit or specify the type of information you want when querying schema information. Numerous Schema Methods are described in the documentation beginning with Understanding Apex Describe Information. There's also additional info on sObjectDescribeResults. Armed with that information, you should be able to specify pretty much the exact information you're looking for.

  • I'm aware of the methods. What I don't know is which of them will narrow the results appropriately, or in other words, what is the discriminating difference for those objects that are available in the Schema Builder. Do you? – ipavlic Apr 23 '13 at 14:19
  • My apologies, it appears I didn't quite get the full intent of your message. If you're talking about the built-in SF schema builder, it would seem to me that it's a matter of only querying for the information you want. For example, you have the option to specify record types, data categories, top levels, child relationships, etc. Its really a matter of figuring out what you want and which of those is comparable to the Schema Builder. – crmprogdev Apr 23 '13 at 14:53

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.