DescribeSObjectResult Class

Contains methods for describing sObjects.

Namespace

Schema

Usage

None of the methods take an argument.

DescribeSObjectResult Methods

The following are methods for DescribeSObjectResult. All are instance methods.

fields

Follow fields with a field member variable name or with the getMap method.

Signature

public Schema.SObjectTypeFields fields()

Return Value

Type: The return value is a special data type. See the example to learn how to use fields.

Usage

Note

Note

When you describe sObjects and their fields from within an Apex class, custom fields of new field types are returned regardless of the API version that the class is saved in. If a field type, such as the geolocation field type, is available only in a recent API version, components of a geolocation field are returned even if the class is saved in an earlier API version.

Example

Schema.DescribeFieldResult dfr = Schema.SObjectType.Account.fields.Name; 

To get a custom field name, specify the custom field name.

fieldSets

Follow fieldSets with a field set name or with the getMap method.

Signature

public Schema.SObjectTypeFields fieldSets()

Return Value

Type: The return value is a special data type. See the example to learn how to use fieldSets.

Example

Schema.DescribeSObjectResult d = 
  Account.sObjectType.getDescribe();
Map<String, Schema.FieldSet> FsMap = 
  d.fieldSets.getMap();

getChildRelationships()

Returns a list of child relationships, which are the names of the sObjects that have a foreign key to the sObject being described.

Signature

public Schema.ChildRelationship getChildRelationships()

Return Value

Type: List<Schema.ChildRelationship>

Example

For example, the Account object includes Contacts and Opportunities as child relationships.

getDefaultImplementation()

Reserved for future use.

Signature

public String getDefaultImplementation()

Return Value

Type: String

getHasSubtypes()

Reserved for future use.

Signature

To check if Person Accounts are enabled for the current org, use this code snippet: Schema.SObjectType.Account.fields.getMap().containsKey( 'isPersonAccount' );

public Boolean getHasSubtypes()

Return Value

Type: Boolean

getImplementedBy()

Reserved for future use.

Signature

public String getImplementedBy()

Return Value

Type: String

getImplementsInterfaces()

Reserved for future use.

Signature

public String getImplementsInterfaces()

Return Value

Type: String

getIsInterface()

Reserved for future use.

Signature

public Boolean getIsInterface()

Return Value

Type: Boolean

getKeyPrefix()

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).

Signature

public String getKeyPrefix()

Return Value

Type: String

Usage

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()

Returns the object's label, which may or may not match the object name.

Signature

public String getLabel()

Return Value

Type: String

Usage

The object's label might not always 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()

Returns the object's plural label, which may or may not match the object name.

Signature

public String getLabelPlural()

Return Value

Type: String

Usage

The object's plural label might not always 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()

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.

Signature

public String getLocalName()

Return Value

Type: String

getName()

Returns the name of the object.

Signature

public String getName()

Return Value

Type: String

getRecordTypeInfos()

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.

Signature

public List<Schema.RecordTypeInfo> getRecordTypeInfos()

Return Value

Type: List<Schema.RecordTypeInfo>

getRecordTypeInfosByDeveloperName()

Returns a map that matches developer 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.

Signature

public Map<String, Schema.RecordTypeInfo> getRecordTypeInfosByDeveloperName()

Return Value

Type: Map<String, Schema.RecordTypeInfo>

getRecordTypeInfosById()

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.

Signature

public Schema.RecordTypeInfo getRecordTypeInfosById()

Return Value

Type: Map<ID, Schema.RecordTypeInfo>

getRecordTypeInfosByName()

Returns a map that matches record labels to their associated record type. The current user is not required to have access to a record type to see it in this map.

Signature

public Schema.RecordTypeInfo getRecordTypeInfosByName()

Return Value

Type: Map<String, Schema.RecordTypeInfo>

getSObjectDescribeOption()

Returns the effective describe option used by the system for the SObject.

Signature

public Schema.SObjectDescribeOptions getSObjectDescribeOption()

Return Value

Type: Schema.SObjectDescribeOptions

Valid values are:
  • SObjectDescribeOptions.FULL: Indicates eager-load all elements of the describe, including child relationships, up-front at the time of method invocation.
  • SObjectDescribeOptions.DEFERRED: Indicates lazy-load child relationships. This means that all child relationships will not be loaded at the time of first invocation of the method.

getSobjectType()

Returns the Schema.SObjectType object for the sObject. You can use this to create a similar sObject.

Signature

public Schema.SObjectType getSobjectType()

Return Value

Type: Schema.SObjectType

isAccessible()

Returns true if the current user can see this object, false otherwise.

Signature

public Boolean isAccessible()

Return Value

Type: Boolean

isCreateable()

Returns true if the object can be created by the current user, false otherwise.

Signature

public Boolean isCreateable()

Return Value

Type: Boolean

isCustom()

Returns true if the object is a custom object, false if it is a standard object.

Signature

public Boolean isCustom()

Return Value

Type: Boolean

isCustomSetting()

Returns true if the object is a custom setting, false otherwise.

Signature

public Boolean isCustomSetting()

Return Value

Type: Boolean

isDeletable()

Returns true if the object can be deleted by the current user, false otherwise.

Signature

public Boolean isDeletable()

Return Value

Type: Boolean

isDeprecatedAndHidden()

Reserved for future use.

Signature

public Boolean isDeprecatedAndHidden()

Return Value

Type: Boolean

isFeedEnabled()

Returns true if Chatter feeds are enabled for the object, false otherwise. This method is only available for Apex classes and triggers saved using SalesforceAPI version 19.0 and later.

Signature

public Boolean isFeedEnabled()

Return Value

Type: Boolean

isMergeable()

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.

Signature

public Boolean isMergeable()

Return Value

Type: Boolean

isMruEnabled()

Returns true if Most Recently Used (MRU) list functionality is enabled for the object, false otherwise.

Signature

public Boolean isMruEnabled()

Return Value

Type: Boolean

isQueryable()

Returns true if the object can be queried by the current user, false otherwise

Signature

public Boolean isQueryable()

Return Value

Type: Boolean

isSearchable()

Returns true if the object can be searched by the current user, false otherwise.

Signature

public Boolean isSearchable()

Return Value

Type: Boolean

isUndeletable()

Returns true if the object can be undeleted by the current user, false otherwise.

Signature

public Boolean isUndeletable()

Return Value

Type: Boolean

isUpdateable()

Returns true if the object can be updated by the current user, false otherwise.

Signature

public Boolean isUpdateable()

Return Value

Type: Boolean