Newer Version Available

This content describes an older version of this product. View Latest

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 on accessing SObjects, see Accessing All sObjects.

When the "Enable Improved Caching of Org Schema" update is enabled, the result of getGlobalDescribe() can include entities that were previously hidden by enforcing sharing rules using with sharing.

Note

Example

describeDataCategoryGroups(sObjectNames)

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

Signature

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

Parameters

sObjectNames
Type: List<String>

Return Value

Type: List<Schema.DescribeDataCategoryGroupResult>

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 “Work with Articles and Translations” 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

describeSObjects(SObjectTypes, SObjectDescribeOptions)

Describes metadata such as field list and object properties for the specified list of SObjects. The default describe option for this method is SObjectDescribeOptions.DEFERRED, which indicates lazy initialization of describe attributes on first use.

Signature

public static List<Schema.DescribeSObjectResult> describeSObjects(List<String> SObjectTypes, Object SObjectDescribeOptions)

Parameters

SObjectTypes
Type: List<String>
The list of SObject types to describe.
SObjectDescribeOptions
Type: Object
The effective describe option used for the SObject.

Return Value

Type: List<Schema.DescribeSObjectResult>

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 “Service.”

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.

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

Note

Example

This example shows how to call the describeTabs method.

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.

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 “Data Category Visibility” in the Salesforce online help.