The following table describes the methods available for the sObject describe result, the DescribeSObjectResult object. None of the methods take an argument.
| Name | Data Type | Description |
|---|---|---|
| fields | Special | Returns a special data type that should not be used by itself.
Instead, fields should always
be followed by either a field member variable name or the getMap method. For example,Schema.DescribeFieldResult F = Schema.SObjectType.Account.fields.Name; For more information, see Understanding Apex Describe Information. |
| getChildRelationships | List<Schema.ChildRelationship> | Returns a list of child relationships, which are the names of the sObjects that have a foreign key to the sObject being described. For example, the Account object includes Contacts and Opportunities as child relationships. |
| getKeyPrefix | String | Returns the three-character prefix code for the object. Record
IDs are prefixed with three-character codes that specify the type
of the object (for example, accounts have a prefix
of 001 and opportunities
have a prefix of 006). The DescribeSobjectResult object returns a value for objects that have a stable prefix. For object types that do not have a stable or predictable prefix, this field is blank. Client applications that rely on these codes can use this way of determining object type to ensure forward compatibility. |
| getLabel | String | Returns the object's label, which may or may not match the object name. For example, an organization in the medical industry might change the label for Account to Patient. This label is then used in the Salesforce user interface. See the Salesforce online help for more information. |
| getLabelPlural | String | Returns the object's plural label, which may or may not match the object name. For example, an organization in the medical industry might change the plural label for Account to Patients. This label is then used in the Salesforce user interface. See the Salesforce online help for more information. |
| getLocalName | String | Returns the name of the object, similar to the getName method. However, if the object is part of the current namespace, the namespace portion of the name is omitted. |
| getName | String | Returns the name of the object |
| getRecordTypeInfos | List<Schema.RecordTypeInfo> | Returns a list of the record types supported by this object. The current user is not required to have access to a record type to see it in this list. |
| getRecordTypeInfosByID | Map<ID, Schema.RecordTypeInfo> | Returns a map that matches record IDs to their associated record types. The current user is not required to have access to a record type to see it in this map. |
| getRecordTypeInfosByName | Map<String, Schema.RecordTypeInfo> | Returns a map that matches record names to their associated record type. The current user is not required to have access to a record type to see it in this map. |
| getSobjectType | Schema.SObjectType | Returns the Schema.SObjectType object for the sObject. You can use this to create a similar sObject. For more information, see Schema.SObjectType. |
| isAccessible | Boolean | Returns true if the current user can see this field, false otherwise |
| isCreateable | Boolean | Returns true if the object can be created by the current user, false otherwise |
| isCustom | Boolean | Returns true if the object is a custom object, false if it is a standard object |
| isCustomSetting | Boolean | Returns true if the object is a custom setting, false otherwise |
| isDeletable | Boolean | Returns true if the object can be deleted by the current user, false otherwise |
| isDeprecatedAndHidden | Boolean | Reserved for future use. |
| isFeedEnabled | Boolean | Returns true if Chatter feeds are enabled for the object, false otherwise. This method is only available for Apex classes and triggers saved using Salesforce API version 19.0 and later. |
| isMergeable | Boolean | Returns true if the object can be merged with other objects of its type by the current user, false otherwise. true is returned for leads, contacts, and accounts. |
| isQueryable | Boolean | Returns true if the object can be queried by the current user, false otherwise |
| isSearchable | Boolean | Returns true if the object can be searched by the current user, false otherwise |
| isUndeletable | Boolean | Returns true if the object cannot be undeleted by the current user, false otherwise |
| isUpdateable | Boolean | Returns true if the object can be updated by the current user, false otherwise |
If an sObject is a parent object, you can access the child relationship as well as the child sObject using the ChildRelationship object methods.
A ChildRelationship object is returned from the sObject describe result using the getChildRelationship method. For example:
Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe(); List<Schema.ChildRelationship> C = R.getChildRelationships();
You can only use 100getChildRelationships method calls per Apex request. For more information about governor limits, see Understanding Execution Governors and Limits.
The following table describes the methods available as part of the ChildRelationship object. None of the methods take an argument.
| Name | Data Type | Description |
|---|---|---|
| getChildSObject | Schema.SObjectType | Returns the token of the child sObject on which there is a foreign key back to the parent sObject. |
| getField | Schema.SObjectField | Returns the token of the field that has a foreign key back to the parent sObject. |
| getRelationshipName | String | Returns the name of the relationship. |
| isCascadeDelete | Boolean | Returns true if the child object is deleted when the parent object is deleted, false otherwise. |
| isDeprecatedAndHidden | Boolean | Reserved for future use. |
| isRestrictedDelete | Boolean | Returns true if the parent object can't be deleted because it is referenced by a child object, false otherwise. |
If an sObject has a record type associated with it, you can access information about the record type using the RecordTypeInfo object methods.
A RecordTypeInfo object is returned from the sObject describe result using the getRecordTypeInfos method. For example:
Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe(); List<Schema.RecordTypeInfo> RT = R.getRecordTypeInfos();
In addition to the getRecordTypeInfos method, you can use the getRecordTypeInfosById and the getRecordTypeInfosByName methods. These methods return maps that associate RecordTypeInfo with record IDs and record names, respectively.
You can only return 100 RecordTypeInfo objects per Apex request. For more information about governor limits, see Understanding Execution Governors and Limits.
The following example assumes at least one record type has been created for the Account object:
RecordType rt = [SELECT Id,Name FROM RecordType WHERE SobjectType='Account' LIMIT 1];
Schema.DescribeSObjectResult d = Schema.SObjectType.Account;
Map<Id,Schema.RecordTypeInfo> rtMapById = d.getRecordTypeInfosById();
Schema.RecordTypeInfo rtById = rtMapById.get(rt.id);
Map<String,Schema.RecordTypeInfo> rtMapByName = d.getRecordTypeInfosByName();
Schema.RecordTypeInfo rtByName = rtMapByName.get(rt.name);
System.assertEquals(rtById,rtByName);
The following table describes the methods available as part of the RecordTypeInfo object. None of the methods take an argument.
| Name | Data Type | Description |
|---|---|---|
| getName | String | Returns the name of this record type |
| getRecordTypeId | ID | Returns the ID of this record type |
| isAvailable | Boolean | Returns true if this record type is available to the current user, false otherwise. Use this method to display a list of available record types to the user when he or she is creating a new record. |
| isDefaultRecordTypeMapping | Boolean | Returns true if this is the default record type mapping, false otherwise. |