3

I am trying to query some basic information about an object with the tooling api. There is one field that I am really interested in but it seems that it is not possible to query it even though the documentation states that it is a field.

The query looks like this:

SELECT Label, QualifiedApiName,Description,**Required**, DataType 
FROM FieldDefinition 
WHERE EntityDefinition.QualifiedApiName ='Account'

The field that I am unable to query is the "Required" field, I've gone through the documentation and cannot see why I am not able to query this field.

Additional documentation on FieldDefinition: Here

Any advice / workarounds?

0

1 Answer 1

4

required is an attribute of Metadata field on FieldDefinition entity. The Metadata field is of type CustomField and this field type has your attribute. To pull the Metadata field via a Tooling API query on an entity, you have to limit the query to return exactly 1 record in your result set by filtering on DurableId. Tooling REST API resource:

/services/data/v46.0/tooling/query?q=SELECT+Label,DurableId,EntityDefinitionId,Metadata+FROM+FieldDefinition+WHERE+DurableId='Account.Id'

yields this response:

{
  "size" : 1,
  "totalSize" : 1,
  "done" : true,
  "queryLocator" : null,
  "entityTypeName" : "FieldDefinition",
  "records" : [ {
    "attributes" : {
      "type" : "FieldDefinition",
      "url" : "/services/data/v46.0/tooling/sobjects/FieldDefinition/Account.Id"
    },
    "Label" : "Account ID",
    "DurableId" : "Account.Id",
    "EntityDefinitionId" : "Account",
    "Metadata" : {
      "businessOwnerGroup" : null,
      "businessOwnerUser" : null,
      "businessStatus" : null,
      "caseSensitive" : null,
      "customDataType" : null,
      "defaultValue" : null,
      "deleteConstraint" : null,
      "deprecated" : null,
      "description" : null,
      "displayFormat" : null,
      "displayLocationInDecimal" : null,
      "encryptionScheme" : null,
      "escapeMarkup" : null,
      "externalDeveloperName" : null,
      "externalId" : null,
      "formula" : null,
      "formulaTreatBlanksAs" : null,
      "inlineHelpText" : null,
      "isAIPredictionField" : null,
      "isConvertLeadDisabled" : null,
      "isFilteringDisabled" : null,
      "isNameField" : null,
      "isSortingDisabled" : null,
      "label" : null,
      "length" : null,
      "lookupFilter" : null,
      "maskChar" : null,
      "maskType" : null,
      "metadataRelationshipControllingField" : null,
      "populateExistingRows" : null,
      "precision" : null,
      "readOnlyProxy" : null,
      "referenceTargetField" : null,
      "referenceTo" : null,
      "relationshipLabel" : null,
      "relationshipName" : null,
      "relationshipOrder" : null,
      "reparentableMasterDetail" : null,
      "required" : null,
      "restrictedAdminField" : null,
      "scale" : null,
      "securityClassification" : null,
      "startingNumber" : null,
      "stripMarkup" : null,
      "summarizedField" : null,
      "summaryFilterItems" : null,
      "summaryForeignKey" : null,
      "summaryOperation" : null,
      "trackFeedHistory" : null,
      "trackHistory" : null,
      "trackTrending" : null,
      "translateData" : null,
      "type" : null,
      "unique" : null,
      "urls" : null,
      "valueSet" : null,
      "visibleLines" : null,
      "writeRequiresMasterRead" : null
    }
  } ]
}
8
  • 2
    +1. One way I could find is to use IsNillable on FieldDefinition which serves the same purpose.
    – Jayant Das
    Commented Aug 30, 2019 at 17:46
  • Excellent answer, thank you. Now if I wanted to do the same thing for multiple objects and fields would I have to make a http request for each field or is there a way to get all the fields for the entire object in one call containing this data? I noticed that the other end point does not give me the data that I am after (the required field) but it does give me all the fields, /services/data/v45.0/sobjects/Account/describe
    – BreadMAN
    Commented Aug 30, 2019 at 19:18
  • @JayantDas, what do you mean it serves the same purpose? It's showing IsNillable = true on fields that aren't required? Am I missing something?
    – BreadMAN
    Commented Aug 30, 2019 at 19:28
  • @BreadMAN That’s correct. If it was false that would mean the field is required.
    – Jayant Das
    Commented Aug 30, 2019 at 19:32
  • @JayantDas, You are absolutely correct, thank you and the others who have assisted me in this issue. I appreciate it greatly. Case closed.
    – BreadMAN
    Commented Aug 30, 2019 at 19:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .