0

I am trying to retrieve the list of fields which are mandatory and running below query:

SELECT id, DeveloperName,EntityDefinitionId,IsNillable,Label FROM FieldDefinition where EntityDefinitionId= 'OBJID'  LIMIT 200

But results I am getting is incorrect for the Name field. Its mandatory for the object but query showing isNillable = true.

Also returned Id is invalid.

    Id  DeveloperName   EntityDefinitionId  IsNillable  Label
1   000000000000000AAA  Id  01Ib00000011OSj false   Record ID
2   000000000000000AAA  Owner   01Ib00000011OSj false   Owner
3   000000000000000AAA  IsDeleted   01Ib00000011OSj false   Deleted
4   000000000000000AAA  Name    01Ib00000011OSj true    Name
5   000000000000000AAA  CurrencyIsoCode 01Ib00000011OSj true    Currency
6   000000000000000AAA  CreatedDate 01Ib00000011OSj false   Created Date
7   000000000000000AAA  CreatedBy   01Ib00000011OSj false   Created By

2 Answers 2

2

This is a Tooling API query. The Id field isn't meaningful here (these are not sObjects). Instead, query the DurableId for an Id value that uniquely identifies this field on this object.

The IsNillable field does return false for the Name field in some circumstances. For example, the Account.Name field is not nillable. For custom objects in my org, Auto Number Name fields are not nillable (even though you don't populate them yourself), but Text Name fields are. Looking at nillability isn't a good way to determine which fields you have to populate in any given circumstance (see sfdcfox's answer for more).

2

Also returned Id is invalid.

No, it's a valid ID, called the "null ID". It means that no ID was returned. This SOQL query returns fields that may or may not have an ID, so it's not appropriate to return an ID to begin with.

Its mandatory for the object but query showing isNillable = true

Name isn't required at the API level. If it's auto-number, then it is never needed, otherwise if no value is given, it populates as the record's ID. This has been pretty standard behavior for a long time. The UI is what requires the Name field, not the API.

You will want to instead describe the page layout using the UI API, REST API, or SOAP API describe calls. The describe calls are the only correct way to determine if a field is required for a given user, page layout, record type, etc.

You must log in to answer this question.

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