DescribeSObjectResult Class

Contains methods for describing SObjects. None of the methods take an argument.

Namespace

Schema

Usage

Instances of describe results on the same DescribeSObjectResult aren’t guaranteed to be equal because the state and behavior of a describe object is determined by various factors including the API version used. To compare describe results, call the getSObjectType() method on the SObject describe results and use the equality operator (==) to compare the SObjectType values.

DescribeSObjectResult Properties

The following are properties for DescribeSObjectResult.

accessible

Indicates whether the current user has access to the SObject.

Signature

public Boolean accessible {get; set;}

Property Value

Type: Boolean

associateentitytype

The type of associated object. For example, History or Share.

Signature

public String associateentitytype {get; set;}

Property Value

Type: String

associateparententity

The parent object of an associated object.

Signature

public String associateparententity {get; set;}

Property Value

Type: String

childrelationships

A list of child relationships, which is the name of the sObject that has a foreign key to the sObject being described.

Signature

public List<Schema.ChildRelationship> childrelationships {get; set;}

Property Value

Type: List<Schema.ChildRelationship>

createable

Indicates whether the SObject can be created by the current user.

Signature

public Boolean createable {get; set;}

Property Value

Type: Boolean

custom

Indicates whether the SObject is a custom object.

Signature

public Boolean custom {get; set;}

Property Value

Type: Boolean

customsetting

Indicates whether the SObject is a custom setting.

Signature

public Boolean customsetting {get; set;}

Property Value

Type: Boolean

datatranslationenabled

Indicates whether data translation is enabled for the SObject. This property is available in API version 49.0 and later.

Signature

public Boolean datatranslationenabled {get; set;}

Property Value

Type: Boolean

defaultimplementation

Reserved for future use.

Signature

public String defaultimplementation {get; set;}

Property Value

Type: String

deletable

Indicates whether the SObject can be deleted by the current user.

Signature

public Boolean deletable {get; set;}

Property Value

Type: Boolean

deprecatedandhidden

Reserved for future use.

Signature

public Boolean deprecatedandhidden {get; set;}

Property Value

Type: Boolean

feedenabled

Indicates whether Chatter feeds are enabled for the SObject.

Signature

public Boolean feedenabled {get; set;}

Property Value

Type: Boolean

fields

A list of fields associated with the SObject.

Signature

public Schema.SObjectTypeFields fields {get; set;}

Property Value

Type: Schema.SObjectTypeFields

Follow fields with the getMap method.

Example

This sample code shows how to use fields. To get a custom field, specify the custom field name.

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

fieldSets

Represents field sets, which is a grouping of the SObject fields.

Signature

public Schema.SObjectTypeFieldSets fieldsets {get; set;}

Property Value

Type: Schema.SObjectTypeFieldSets

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

Example

This sample code shows how to use fieldSet.
Schema.DescribeSObjectResult d = 
  Account.sObjectType.getDescribe();
Map<String, Schema.FieldSet> FsMap = 
  d.fieldSets.getMap();

hassubtypes

Reserved for future use.

Signature

public Boolean hassubtypes {get; set;}

Property Value

Type: Boolean

implementedby

Reserved for future use.

Signature

public String implementedby {get; set;}

Property Value

Type: String

implementsinterfaces

Reserved for future use.

Signature

public String implementsinterfaces {get; set;}

Property Value

Type: String

isinterface

Reserved for future use.

Signature

public Boolean isinterface {get; set;}

Property Value

Type: Boolean

keyprefix

The three-character prefix code in the SObject ID.

Signature

public String keyprefix {get; set;}

Property Value

Type: String

label

The SObject's label, which may or may not match the object name. For example, an organization representing a medical vertical might rename Account to Patient. Tabs and fields can be renamed in the Salesforce user interface.

Signature

public String label {get; set;}

Property Value

Type: String

labelplural

The SObject's plural label, which may or may not match the object name. For example, Accounts.

Signature

public String labelplural {get; set;}

Property Value

Type: String

localname

The name of the SObject. If the object is part of the current namespace, the namespace portion of the name is omitted.

Signature

public String localname {get; set;}

Property Value

Type: String

mergeable

Indicates whether the SObject can be merged with other objects of its type by the current user. This is set to true for leads, contacts, and accounts.

Signature

public Boolean mergeable {get; set;}

Property Value

Type: Boolean

mruenabled

Indicates whether Most Recently Used (MRU) list functionality is enabled for the SObject.

Signature

public Boolean mruenabled {get; set;}

Property Value

Type: Boolean

name

The name field of the SObject.

Signature

public String name {get; set;}

Property Value

Type: String

queryable

Indicates whether the SObject can be queried by the current user.

Signature

public Boolean queryable {get; set;}

Property Value

Type: Boolean

recordtypeinfos

A list of the record types supported by the SObject.

Signature

public List<Schema.RecordTypeInfo> recordtypeinfos {get; set;}

Property Value

Type: List<Schema.RecordTypeInfo>

recordtypeinfosbydevelopername

A map that matches developer names to their associated record type.

Signature

public Map<String,Schema.RecordTypeInfo> recordtypeinfosbydevelopername {get; set;}

Property Value

Type: Map<String, Schema.RecordTypeInfo>

recordtypeinfosbyid

A map that matches record IDs to their associated record types.

Signature

public Map<Id,Schema.RecordTypeInfo> recordtypeinfosbyid {get; set;}

Property Value

Type: Map<ID, Schema.RecordTypeInfo>

recordtypeinfosbyname

A map that matches record labels to their associated record type.

Signature

public Map<String,Schema.RecordTypeInfo> recordtypeinfosbyname {get; set;}

Property Value

Type: Map<String, Schema.RecordTypeInfo>

searchable

Indicates whether the SObject can be searched by the current user.

Signature

public Boolean searchable {get; set;}

Property Value

Type: Boolean

sobjectdescribeoption

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

Signature

public Schema.SObjectDescribeOptions sobjectdescribeoption {get; set;}

Property Value

Type: Schema.SObjectDescribeOptions

sobjecttype

The Schema.SObjectType object for the SObject.

Signature

public Schema.SObjectType sobjecttype {get; set;}

Property Value

Type: Schema.SObjectType

undeletable

Indicates whether the SObject can be undeleted by the current user.

Signature

public Boolean undeletable {get; set;}

Property Value

Type: Boolean

updateable

Indicates whether the SObject can be updated by the current user.

Signature

public Boolean updateable {get; set;}

Property Value

Type: Boolean

DescribeSObjectResult Methods

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

equals(obj)

Compares the SObject to the specified object and returns true if both are equal. Otherwise, returns false.

Signature

public Boolean equals(Object obj)

Parameters

obj
Type: Object
The object with which to compare.

Return Value

Type: Boolean

getAssociateEntityType()

Returns additional metadata for an associated object of a specified parent but only if it's a specific associated object type. Used in combination with the getAssociateParentEntity() method to get the parent object. For example, invoking the method on AccountHistory returns the parent object as Account and the type of associated object as History.

Signature

public String associateentitytype {get; set;}

Return Value

Type: String

getAssociateParentEntity()

Returns additional metadata for an associated object but only if it's associated to a specific parent object. Used in combination with the getAssociateEntityType() method to get the type of associated object. For example, invoking the method on AccountHistory returns the parent object as Account and the type of associated object as History.

Signature

public String getAssociateParentEntity()

Return Value

Type: String

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.

getDataTranslationEnabled()

Returns true if data translation is enabled for the SObject. Otherwise, returns false.

Signature

public Boolean getDataTranslationEnabled()

Return Value

Type: Boolean

getDefaultImplementation()

Reserved for future use.

Signature

public String getDefaultImplementation()

Return Value

Type: String

getFields()

Returns the fields that make up the SObject being described.

Signature

public Schema.SObjectTypeFields getFields()

Return Value

Type: Schema.SObjectTypeFields

The return value is a special data type. Call the getMap() method to get a map of Strings and SObjectFields.

Usage

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.

getFieldSets()

Returns field sets, which is a grouping of the SObject fields.

Signature

public Schema.SObjectTypeFieldSets getFieldSets()

Return Value

Type: Schema.SObjectTypeFieldSets

The return value is a special data type. Call the getMap() method to get a map of Strings and SObjectFieldSets.

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

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

hashCode()

Returns the hash code for the SObject.

Signature

public Integer hashCode()

Return Value

Type: Integer

isAccessible()

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

Signature

public Boolean isAccessible()

Return Value

Type: Boolean

Versioned Behavior Changes

In API version 54.0 and later, for custom settings and custom metadata type objects, DescribeSObjectResult.isAccessible() returns false if the user doesn’t have permissions to access the queried objects. In API version 53.0 and earlier, the method returns true even if the user doesn't have the required permissions.

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

toString()

Returns a string that represents the SObject.

Signature

public String toString()

Return Value

Type: String