DescribeFieldResult Class
Contains methods for describing sObject fields.
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.
-
For variable-length fields (including binary fields), returns the maximum size of the field, in bytes.
-
Returns the formula specified for this field.
-
Returns the token of the controlling field.
-
Returns the default value for this field.
-
Returns the default formula value that is specified for this formula field.
-
Returns the maximum number of digits specified for the field. This method is only valid with Integer fields.
-
Returns the content of the field-level help.
-
Returns the text label that is displayed next to the field in the Salesforce user interface. This label can be localized.
-
Returns the maximum size of the field for the DescribeFieldResult object in Unicode characters (not bytes).
-
Returns the name of the field, similar to the
getNamemethod. However, if the field is part of the current namespace, the namespace portion of the name is omitted. -
Returns the field name used in Apex.
-
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.
-
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).
-
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.
-
Returns a list of Schema.sObjectType objects for the parent objects of this field. If the
isNamePointingmethod returnstrue, there is more than one entry in the list, otherwise there is only one. -
Returns the name of the child-to-parent relationship.
-
Returns 0 if the field is the primary relationship field or 1 if the field is the secondary relationship field.
-
For fields of type Double, returns the number of digits to the right of the decimal point.
-
Returns one of the SoapType enum values, depending on the type of field.
-
Returns the token for this field.
-
Returns the Salesforce object type from which this field originates.
-
Returns one of the DisplayType enum values, depending on the type of field.
-
Returns
trueif the current user can see this field,falseotherwise. -
Returns
trueif the current field is enabled to display Einstein prediction data,falseotherwise. -
Returns
trueif the field is an Auto Number field,falseotherwise. -
Returns
trueif the field is a custom formula field,falseotherwise. Note that custom formula fields are always read-only. -
Returns
trueif the child object is deleted when the parent object is deleted,falseotherwise. -
Returns
trueif the field is case sensitive,falseotherwise. -
Returns
trueif the field can be created by the current user,falseotherwise. -
Returns
trueif the field is a custom field,falseif it is a standard field, such asName. -
Returns
trueif the field receives a default value when created,falseotherwise. -
Returns
trueif the picklist is a dependent picklist,falseotherwise. -
Reserved for future use.
-
Returns
trueif the field is encrypted with Shield Platform Encryption,falseotherwise. -
Returns
trueif the field is used as an external ID,falseotherwise. -
Returns
trueif the field can be used as part of the filter criteria of aWHEREstatement,falseotherwise. -
isFormulaTreatNullNumberAsZero()
Returns
trueifnullis treated as zero in a formula field,falseotherwise. -
Returns
trueif the field can be included in theGROUP BYclause of a SOQL query,falseotherwise. This method is only available for Apex classes and triggers saved using API version 18.0 and higher. -
Returns
trueif the field has been formatted for HTML and should be encoded for display in HTML,falseotherwise. One example of a field that returnstruefor this method is a hyperlink custom formula field. Another example is a custom formula field that has anIMAGEtext function. -
Returns
trueif the field can be used to specify a record in anupsertmethod,falseotherwise. -
Returns
trueif the field is a name field,falseotherwise. -
Returns
trueif the field can have multiple types of objects as parents. For example, a task can have both theContact/Lead ID(WhoId) field and theOpportunity/Account ID(WhatId) field returntruefor this method. because either of those objects can be the parent of a particular task record. This method returnsfalseotherwise. -
Returns
trueif the field is nillable,falseotherwise. A nillable field can have empty content. A non-nillable field must have a value for the object to be created or saved. -
Returns
trueif field permissions can be specified for the field,falseotherwise. -
Returns
trueif the parent object can’t be deleted because it is referenced by a child object,falseotherwise. -
Returns
trueif the field is a restricted picklist,falseotherwise -
Returns
trueif a foreign key can be included in prefiltering when used in a SOSLWHEREclause,falseotherwise. -
Returns
trueif a query can sort on the field,falseotherwise -
Returns
trueif the value for the field must be unique,falseotherwise -
Returns
trueif 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;falseotherwise. -
Returns
trueif 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