DescribeFieldResult Class

Contains methods for describing sObject fields.

Schema

Instances of field describe results on the same DescribeFieldResult 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 getSObjectField() method on the field describe results and use the equality operator (==) to compare the SObjectField values.

The following is an example of how to instantiate a field describe result object:

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

  • getByteLength()

    For variable-length fields (including binary fields), returns the maximum size of the field, in bytes.

  • getCalculatedFormula()

    Returns the formula specified for this field.

  • getController()

    Returns the token of the controlling field.

  • getDefaultValue()

    Returns the default value for this field.

  • getDefaultValueFormula()

    Returns the default formula value that is specified for this formula field.

  • getDigits()

    Returns the maximum number of digits specified for the field. This method is only valid with Integer fields.

  • getInlineHelpText()

    Returns the content of the field-level help.

  • getLabel()

    Returns the text label that is displayed next to the field in the Salesforce user interface. This label can be localized.

  • getLength()

    Returns the maximum size of the field for the DescribeFieldResult object in Unicode characters (not bytes).

  • getLocalName()

    Returns the name of the field, similar to the getName method. However, if the field is part of the current namespace, the namespace portion of the name is omitted.

  • getName()

    Returns the field name used in Apex.

  • getPicklistValues()

    Returns a list of active PicklistEntry objects. A runtime error is returned if the field isn’t a picklist. Only active picklist values are returned.

  • getPrecision()

    For fields of type Double, returns the maximum number of digits that can be stored, including all numbers to the left and to the right of the decimal point (but excluding the decimal point character).

  • getReferenceTargetField()

    Returns the name of the custom field on the parent standard or custom object whose values are matched against the values of the child external object’s indirect lookup relationship field. The match is done to determine which records are related to each other.

  • getReferenceTo()

    Returns a list of Schema.sObjectType objects for the parent objects of this field. If the isNamePointing method returns true, there is more than one entry in the list, otherwise there is only one.

  • getRelationshipName()

    Returns the name of the child-to-parent relationship.

  • getRelationshipOrder()

    Returns 0 if the field is the primary relationship field or 1 if the field is the secondary relationship field.

  • getScale()

    For fields of type Double, returns the number of digits to the right of the decimal point.

  • getSOAPType()

    Returns one of the SoapType enum values, depending on the type of field.

  • getSObjectField()

    Returns the token for this field.

  • getSObjectType()

    Returns the Salesforce object type from which this field originates.

  • getType()

    Returns one of the DisplayType enum values, depending on the type of field.

  • isAccessible()

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

  • isAiPredictionField() (Beta)

    Returns true if the current field is enabled to display Einstein prediction data, false otherwise.

  • isAutoNumber()

    Returns true if the field is an Auto Number field, false otherwise.

  • isCalculated()

    Returns true if the field is a custom formula field, false otherwise. Note that custom formula fields are always read-only.

  • isCascadeDelete()

    Returns true if the child object is deleted when the parent object is deleted, false otherwise.

  • isCaseSensitive()

    Returns true if the field is case sensitive, false otherwise.

  • isCreateable()

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

  • isCustom()

    Returns true if the field is a custom field, false if it is a standard field, such as Name.

  • isDefaultedOnCreate()

    Returns true if the field receives a default value when created, false otherwise.

  • isDependentPicklist()

    Returns true if the picklist is a dependent picklist, false otherwise.

  • isDeprecatedAndHidden()

    Reserved for future use.

  • isEncrypted()

    Returns true if the field is encrypted with Shield Platform Encryption, false otherwise.

  • isExternalID()

    Returns true if the field is used as an external ID, false otherwise.

  • isFilterable()

    Returns true if the field can be used as part of the filter criteria of a WHERE statement, false otherwise.

  • isFormulaTreatNullNumberAsZero()

    Returns true if null is treated as zero in a formula field, false otherwise.

  • isGroupable()

    Returns true if the field can be included in the GROUP BY clause of a SOQL query, false otherwise. This method is only available for Apex classes and triggers saved using API version 18.0 and higher.

  • isHtmlFormatted()

    Returns true if the field has been formatted for HTML and should be encoded for display in HTML, false otherwise. One example of a field that returns true for this method is a hyperlink custom formula field. Another example is a custom formula field that has an IMAGE text function.

  • isIdLookup()

    Returns true if the field can be used to specify a record in an upsert method, false otherwise.

  • isNameField()

    Returns true if the field is a name field, false otherwise.

  • isNamePointing()

    Returns true if the field can have multiple types of objects as parents. For example, a task can have both the Contact/Lead ID (WhoId) field and the Opportunity/Account ID (WhatId) field return true for this method. because either of those objects can be the parent of a particular task record. This method returns false otherwise.

  • isNillable()

    Returns true if the field is nillable, false otherwise. A nillable field can have empty content. A non-nillable field must have a value for the object to be created or saved.

  • isPermissionable()

    Returns true if field permissions can be specified for the field, false otherwise.

  • isRestrictedDelete()

    Returns true if the parent object can’t be deleted because it is referenced by a child object, false otherwise.

  • isRestrictedPicklist()

    Returns true if the field is a restricted picklist, false otherwise

  • isSearchPrefilterable()

    Returns true if a foreign key can be included in prefiltering when used in a SOSL WHERE clause, false otherwise.

  • isSortable()

    Returns true if a query can sort on the field, false otherwise

  • isUnique()

    Returns true if the value for the field must be unique, false otherwise

  • isUpdateable()

    Returns true if the field can be edited by the current user, or child records in a master-detail relationship field on a custom object can be reparented to different parent records; false otherwise.

  • isWriteRequiresMasterRead()

    Returns true if writing to the detail object requires read sharing instead of read/write sharing of the parent.

For variable-length fields (including binary fields), returns the maximum size of the field, in bytes.

public Integer getByteLength()

Type: Integer

Returns the formula specified for this field.

public String getCalculatedFormula()

Type: String

Returns the token of the controlling field.

public Schema.sObjectField getController()

Type: Schema.SObjectField

Returns the default value for this field.

public Object getDefaultValue()

Type: Object

Returns the default formula value that is specified for this formula field.

public String getDefaultValueFormula()

Type: String

Returns the maximum number of digits specified for the field. This method is only valid with Integer fields.

public Integer getDigits()

Type: Integer

Returns the content of the field-level help.

public String getInlineHelpText()

Type: String

For more information, see “Define Field-Level Help” in the Salesforce online help.

Returns the text label that is displayed next to the field in the Salesforce user interface. This label can be localized.

public String getLabel()

Type: String

For the Type field on standard objects, getLabel returns a label different from the default label. It returns a label of the form Object Type, where Object is the standard object label. For example, for the Type field on Account, getLabel returns Account Type instead of the default label Type. If the Type label is renamed, getLabel returns the new label. You can check or change the labels of all standard object fields from Setup by entering Rename Tabs and Labels in the Quick Find box, then selecting Rename Tabs and Labels.

Returns the maximum size of the field for the DescribeFieldResult object in Unicode characters (not bytes).

public Integer getLength()

Type: Integer

Returns the name of the field, similar to the getName method. However, if the field is part of the current namespace, the namespace portion of the name is omitted.

public String getLocalName()

Type: String

Returns the field name used in Apex.

public String getName()

Type: String

Returns a list of active PicklistEntry objects. A runtime error is returned if the field isn’t a picklist. Only active picklist values are returned.

public List<Schema.PicklistEntry> getPicklistValues()

Type: List<Schema.PicklistEntry>

For fields of type Double, returns the maximum number of digits that can be stored, including all numbers to the left and to the right of the decimal point (but excluding the decimal point character).

public Integer getPrecision()

Type: Integer

Returns the name of the custom field on the parent standard or custom object whose values are matched against the values of the child external object’s indirect lookup relationship field. The match is done to determine which records are related to each other.

public String getReferenceTargetField()

Type: String

For information about indirect lookup relationships, see “Indirect Lookup Relationship Fields on External Objects” in the Salesforce Help.

Returns a list of Schema.sObjectType objects for the parent objects of this field. If the isNamePointing method returns true, there is more than one entry in the list, otherwise there is only one.

public List <Schema.sObjectType> getReferenceTo()

Type: List<Schema.sObjectType>

In API version 51.0 and later, the getReferenceTo() method returns referenced objects that aren’t accessible to the context user. If the context user has access to an object’s field that references another object, irrespective of the context user’s access to the cross-referenced object, the method returns references. In API version 50.0 and earlier, if the context user doesn’t have access to the cross-referenced object, the method returns an empty list.

Returns the name of the child-to-parent relationship.

public String getRelationshipName()

Type: String

For more information about relationships and relationship names, see Understanding Relationship Names in the SOQL and SOSL Reference.

Returns 0 if the field is the primary relationship field or 1 if the field is the secondary relationship field.

public Integer getRelationshipOrder()

Type: Integer

For more information about primary and secondary relationships, see Considerations for Object Relationships. For more information about relationships and relationship names, see Understanding Relationship Names in the SOQL and SOSL Reference.

For fields of type Double, returns the number of digits to the right of the decimal point.

public Integer getScale()

Type: Integer

Returns one of the SoapType enum values, depending on the type of field.

public Schema.SOAPType getSOAPType()

Type: Schema.SOAPType

Returns the token for this field.

public Schema.sObjectField getSObjectField()

Type: Schema.SObjectField

Returns the Salesforce object type from which this field originates.

public Schema.SObjectType getSObjectType()

Type: Schema.SObjectType

Returns one of the DisplayType enum values, depending on the type of field.

public Schema.DisplayType getType()

Type: Schema.DisplayType

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

public Boolean isAccessible()

Type: Boolean

Returns true if the current field is enabled to display Einstein prediction data, false otherwise.

public Boolean isAiPredictionField()

Type: Boolean

Custom number fields can be set to display Einstein prediction values. If you are participating in the Einstein Prediction Builder Beta program, use Einstein Prediction Builder to set up the value to display. Use this method to find out if a field is enabled to display an Einstein prediction value.

Returns true if the field is an Auto Number field, false otherwise.

public Boolean isAutoNumber()

Type: Boolean

Analogous to a SQL IDENTITY type, Auto Number fields are read-only, non-createable text fields with a maximum length of 30 characters. Auto Number fields are used to provide a unique ID that is independent of the internal object ID (such as a purchase order number or invoice number). Auto Number fields are configured entirely in the Salesforce user interface.

Returns true if the field is a custom formula field, false otherwise. Note that custom formula fields are always read-only.

public Boolean isCalculated()

Type: Boolean

Returns true if the child object is deleted when the parent object is deleted, false otherwise.

public Boolean isCascadeDelete()

Type: Boolean

Returns true if the field is case sensitive, false otherwise.

public Boolean isCaseSensitive()

Type: Boolean

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

public Boolean isCreateable()

Type: Boolean

Returns true if the field is a custom field, false if it is a standard field, such as Name.

public Boolean isCustom()

Type: Boolean

Returns true if the field receives a default value when created, false otherwise.

public Boolean isDefaultedOnCreate()

Type: Boolean

If this method returns true, Salesforce implicitly assigns a value for this field when the object is created, even if a value for this field is not passed in on the create call. For example, in the Opportunity object, the Probability field has this attribute because its value is derived from the Stage field. Similarly, the Owner has this attribute on most objects because its value is derived from the current user (if the Owner field is not specified).

Returns true if the picklist is a dependent picklist, false otherwise.

public Boolean isDependentPicklist()

Type: Boolean

Reserved for future use.

public Boolean isDeprecatedAndHidden()

Type: Boolean

Returns true if the field is encrypted with Shield Platform Encryption, false otherwise.

public Boolean isEncrypted()

Type: Boolean

Returns true if the field is used as an external ID, false otherwise.

public Boolean isExternalID()

Type: Boolean

Returns true if the field can be used as part of the filter criteria of a WHERE statement, false otherwise.

public Boolean isFilterable()

Type: Boolean

Returns true if null is treated as zero in a formula field, false otherwise.

public Boolean isFormulaTreatNullNumberAsZero()

Type: Boolean

Returns true if the field can be included in the GROUP BY clause of a SOQL query, false otherwise. This method is only available for Apex classes and triggers saved using API version 18.0 and higher.

public Boolean isGroupable()

Type: Boolean

Returns true if the field has been formatted for HTML and should be encoded for display in HTML, false otherwise. One example of a field that returns true for this method is a hyperlink custom formula field. Another example is a custom formula field that has an IMAGE text function.

public Boolean isHtmlFormatted()

Type: Boolean

Returns true if the field can be used to specify a record in an upsert method, false otherwise.

public Boolean isIdLookup()

Type: Boolean

Returns true if the field is a name field, false otherwise.

public Boolean isNameField()

Type: Boolean

This method is used to identify the name field for standard objects (such as AccountName for an Account object) and custom objects. Objects can only have one name field, except where the FirstName and LastName fields are used instead (such as on the Contact object).

If a compound name is present, for example, the Name field on a person account, isNameField is set to true for that record.

Returns true if the field can have multiple types of objects as parents. For example, a task can have both the Contact/Lead ID (WhoId) field and the Opportunity/Account ID (WhatId) field return true for this method. because either of those objects can be the parent of a particular task record. This method returns false otherwise.

public Boolean isNamePointing()

Type: Boolean

Returns true if the field is nillable, false otherwise. A nillable field can have empty content. A non-nillable field must have a value for the object to be created or saved.

public Boolean isNillable()

Type: Boolean

Returns true if field permissions can be specified for the field, false otherwise.

public Boolean isPermissionable()

Type: Boolean

Returns true if the parent object can’t be deleted because it is referenced by a child object, false otherwise.

public Boolean isRestrictedDelete()

Type: Boolean

Returns true if the field is a restricted picklist, false otherwise

public Boolean isRestrictedPicklist()

Type: Boolean

Returns true if a foreign key can be included in prefiltering when used in a SOSL WHERE clause, false otherwise.

public Boolean isSearchPrefilterable()

Type: Boolean

Prefiltering means to filter by a specific field value before executing the full search query. Prefiltering is supported only in WHERE clauses with the equals (=) operator.

Returns true if a query can sort on the field, false otherwise

public Boolean isSortable()

Type: Boolean

Returns true if the value for the field must be unique, false otherwise

public Boolean isUnique()

Type: Boolean

Returns true if the field can be edited by the current user, or child records in a master-detail relationship field on a custom object can be reparented to different parent records; false otherwise.

Where possible, we changed noninclusive terms to align with our company value of Equality. We maintained certain terms to avoid any effect on customer implementations.

public Boolean isUpdateable()

Type: Boolean

Returns true if writing to the detail object requires read sharing instead of read/write sharing of the parent.

public Boolean isWriteRequiresMasterRead()

Type: Boolean