The following table describes the methods available for the sObject describe result, the DescribeSObjectResult object. None of the methods take an argument.
Description Data Type
Name
Returns a special data type that should not be used by itself. Instead,fields should always be followed Special
fields
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 Using Field Describe Results on page 104.
Returns a list of child relationships, which are the names of the sObjects that have a foreign key to the List<Schema.ChildRelationship>
getChildRelationships
sObject being described. For example, the Account object includes Contacts and Opportunities as child relationships.
Returns the three-character prefix code for the object.
Record IDs are prefixed with three-character codes String
getKeyPrefix
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.
Returns the object's label, which may or may not match the object name. For example, an organization String
getLabel
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.
Returns the object's plural label, which may or may not match the object name. For example, an String
getLabelPlural
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.
Returns the name of the object, similar to the getName method. However, if the object is part of String
getLocalName
the current namespace, the namespace portion of the name is omitted.
sObject Describe Result Methods
Description Data Type
Name
Returns the name of the object String
getName
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.
List<Schema.RecordTypeInfo>
getRecordTypeInfos
Returns a map that matches record IDs to their associated record types. The current user is not Map<ID,
Schema.RecordTypeInfo>
getRecordTypeInfosByID
required to have access to a record type to see it in this map.
Returns a map that matches record names to their associated record type. The current user is not Map<String,
Schema.RecordTypeInfo>
getRecordTypeInfosByName
required to have access to a record type to see it in this map.
Returns true if the current user can see this field, false otherwise
Boolean isAccessible
Returns true if the object can be created by the current user,false otherwise
Boolean isCreateable
Returns true if the object is a custom object,false if it is a standard object
Boolean isCustom
Returns true if the object can be deleted by the current user,false otherwise
Boolean isDeletable
Returns true if the object can be merged with other objects of its type by the current user,false Boolean
isMergeable
otherwise.true is returned for leads, contacts, and accounts.
Returns true if the object can be queried by the current user,false otherwise
Boolean isQueryable
Returns true if the object can be searched by the current user,false otherwise
Boolean isSearchable
Returns true if an Apex trigger is available on this object,false otherwise
Boolean isTriggerable
Returns true if the object cannot be undeleted by the current user,false otherwise
Boolean isUndeleteable
Returns true if the object can be updated by the current user,false otherwise
Boolean isUpdateable
ChildRelationship Methods
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:
sObject Describe Result Methods
You can only use 10getChildRelationships method calls per sObject during the execution of an Apex script. For example, an Apex script can execute 10 getChildRelationships method calls for Account, then another 10 for Lead. For more information about governor limits, see Understanding Execution Governors and Limits on page 142.
The following table describes the methods available as part of the ChildRelationship object. None of the methods take an argument.
Description Data Type
Name
Returns the token of the child sObject on which there is a foreign key back to the parent sObject.
Schema.SObjectType getChildSObject
Returns the token of the field that has a foreign key back to the parent sObject.
Schema.SObjectField getField
Returns the name of the relationship.
String getRelationshipName
Returns true if the child object is deleted when the parent object is deleted,false otherwise.
Boolean isCascadeDelete
RecordTypeInfo Methods
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 10 RecordTypeInfo objects per sObject during the execution of an Apex script. For example, an Apex script can execute 10getRecordTypeInfosByName method calls for Account, then another 10 for Lead. For more information about governor limits, see Understanding Execution Governors and Limits on page 142.
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;
The following table describes the methods available as part of the RecordTypeInfo object. None of the methods take an argument.
Description Data Type
Name
Returns the name of this record type String
getName
Returns the ID of this record type ID
getRecordTypeId
Returns true if this record type is available to the current user,false otherwise. Use this method to Boolean
isAvailable
sObject Describe Result Methods
Description Data Type
Name
display a list of available record types to the user when he or she is creating a new record.
Returns true if this is the default record type mapping,false otherwise.
Boolean isDefaultRecordTypeMapping