Schema Class

Contains methods for obtaining schema describe information.

Namespace

System

Schema Methods

The following are methods for Schema. All methods are static.

getGlobalDescribe()

Returns a map of all sObject names (keys) to sObject tokens (values) for the standard and custom objects defined in your organization.

Signature

public static Map<String, Schema.SObjectType> getGlobalDescribe()

Return Value

Type: Map<String, Schema.SObjectType>

Usage

For more information, see Accessing All sObjects.

Example

Map<String, Schema.SObjectType> gd = 
Schema.getGlobalDescribe(); 

describeDataCategoryGroups(sObjectNames)

Returns a list of the category groups associated with the specified objects.

Signature

public static List<Schema.DescribeDataCategoryGroupResult> describeDataCategoryGroups(String sObjectNames)

Parameters

sObjectNames
Type: List<String>

Usage

You can specify one of the following sObject names:

  • KnowledgeArticleVersion—to retrieve category groups associated with article types.
  • Question—to retrieve category groups associated with questions.

For more information and code examples using describeDataCategoryGroups, see Accessing All Data Categories Associated with an sObject.

For additional information about articles and questions, see “Managing Articles and Translations” and “Answers Overview” in the Salesforce online help.

describeSObjects(sObjectTypes)

Describes metadata (field list and object properties) for the specified sObject or array of sObjects.

Signature

public static List<Schema.DescribeSObjectResult> describeSObjects(List<String> sObjectTypes)

Parameters

sObjectTypes
Type: List<String>
The sObjectTypes argument is a list of sObject type names you want to describe.

Return Value

Type: List<Schema.DescribeSObjectResult>

Usage

This method is similar to the getDescribe method on the Schema.sObjectType token. Unlike the getDescribe method, this method allows you to specify the sObject type dynamically and describe more than one sObject at a time.

You can first call getGlobalDescribe to retrieve a list of all objects for your organization, then iterate through the list and use describeSObjects to obtain metadata about individual objects.

Example

Schema.DescribeSObjectResult[] descResult = Schema.describeSObjects(
                                                                   new String[]{'Account','Contact'});

describeTabs()

Returns information about the standard and custom apps available to the running user.

Signature

public static List<Schema.DescribeTabSetResult> describeTabs()

Return Value

Type: List<Schema.DescribeTabSetResult>

Usage

An app is a group of tabs that works as a unit to provide application functionality. For example, two of the standard Salesforce apps are “Sales” and “Call Center.”

The describeTabs method returns the minimum required metadata that can be used to render apps in another user interface. Typically, this call is used by partner applications to render Salesforce data in another user interface, such as in a mobile or connected app.

In the Salesforce user interface, users have access to standard apps (and might also have access to custom apps) as listed in the Salesforce app menu at the top of the page. Selecting an app name in the menu allows the user to switch between the listed apps at any time.

Note

Note

The “All Tabs” tab isn’t included in the list of described tabs.

Example

This example shows how to call the describeTabs method.

Schema.DescribeTabSetResult[] tabSetDesc = Schema.describeTabs();

This is a longer example that shows how to obtain describe metadata information for the Sales app. For each tab, the example gets describe information, such as the icon URL, whether the tab is custom or not, and colors. The describe information is written to the debug output.

// Get tab set describes for each app
List<Schema.DescribeTabSetResult> tabSetDesc = Schema.describeTabs();

// Iterate through each tab set describe for each app and display the info
for(DescribeTabSetResult tsr : tabSetDesc) {
    String appLabel = tsr.getLabel();
    System.debug('Label: ' + appLabel);
    System.debug('Logo URL: ' + tsr.getLogoUrl());
    System.debug('isSelected: ' + tsr.isSelected());
    String ns = tsr.getNamespace();
    if (ns == '') {
        System.debug('The ' + appLabel + ' app has no namespace defined.');
    }
    else {
        System.debug('Namespace: ' + ns);
    }
    
    // Display tab info for the Sales app
    if (appLabel == 'Sales') {
        List<Schema.DescribeTabResult> tabDesc = tsr.getTabs();
        System.debug('-- Tab information for the Sales app --');
        for(Schema.DescribeTabResult tr : tabDesc) {
            System.debug('getLabel: ' + tr.getLabel());
            System.debug('getColors: ' + tr.getColors());
            System.debug('getIconUrl: ' + tr.getIconUrl());
            System.debug('getIcons: ' + tr.getIcons());
            System.debug('getMiniIconUrl: ' + tr.getMiniIconUrl());
            System.debug('getSobjectName: ' + tr.getSobjectName());
            System.debug('getUrl: ' + tr.getUrl());
            System.debug('isCustom: ' + tr.isCustom());
        }
    }            
}
// Example debug statement output
// DEBUG|Label: Sales
// DEBUG|Logo URL: https://na1.salesforce.com/img/seasonLogos/2014_winter_aloha.png
// DEBUG|isSelected: true
// DEBUG|The Sales app has no namespace defined.// DEBUG|-- Tab information for the Sales app --
// (This is an example debug output for the Accounts tab.)
// DEBUG|getLabel: Accounts
// DEBUG|getColors: (Schema.DescribeColorResult[getColor=236FBD;getContext=primary;getTheme=theme4;], 
//       Schema.DescribeColorResult[getColor=236FBD;getContext=primary;getTheme=theme3;], 
//       Schema.DescribeColorResult[getColor=236FBD;getContext=primary;getTheme=theme2;])
// DEBUG|getIconUrl: https://na1.salesforce.com/img/icon/accounts32.png
// DEBUG|getIcons: (Schema.DescribeIconResult[getContentType=image/png;getHeight=32;getTheme=theme3;
//       getUrl=https://na1.salesforce.com/img/icon/accounts32.png;getWidth=32;], 
//       Schema.DescribeIconResult[getContentType=image/png;getHeight=16;getTheme=theme3;
//       getUrl=https://na1.salesforce.com/img/icon/accounts16.png;getWidth=16;])
// DEBUG|getMiniIconUrl: https://na1.salesforce.com/img/icon/accounts16.png
// DEBUG|getSobjectName: Account
// DEBUG|getUrl: https://na1.salesforce.com/001/o
// DEBUG|isCustom: false

GroupStructures(pairs)

Returns available category groups along with their data category structure for objects specified in the request.

Signature

public static List<Schema.DescribeDataCategoryGroupStructureResult> describeDataCategory GroupStructures(List<Schema.DataCategoryGroupSobjectTypePair> pairs)

Parameters

pairs
Type: List<Schema.DataCategoryGroupSobjectTypePair>
The pairs argument is one or more category groups and objects to query Schema.DataCategoryGroupSobjectTypePairs. Visible data categories are retrieved for the specified object. For more information on data category group visibility, see “About Category Group Visibility” in the Salesforce online help.