0

I have used this query to obtain up to date results for Field ID for the Contact Object:

SELECT Id,DeveloperName,CreatedDate,CreatedById,Description,EntityDefinitionId,InlineHelpText,LastModifiedById,LastModifiedDate,Length,ManageableState,MaskChar,MaskType,NamespacePrefix,Precision,RelationshipLabel,Scale,SummaryOperation,TableEnumOrId FROM CustomField WHERE TableEnumOrId = 'Contact'

Then I have used the Id value of this query for the IN part of another SOQL query for the UserFieldAccess object:

SELECT DurableId,EntityDefinitionId,FieldDefinitionId,Id,IsAccessible,IsCreatable,IsUpdatable,UserId FROM UserFieldAccess where DurableId IN ('00Nw0000003fCQgEAM','00Nw0000003fCQhEAM',

But this returns zero results?

If I look at the documentation for the UserFieldAccess object: https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_userfieldaccess.htm

DurableId: Unique identifier for the field. Always retrieve this value before using it, as the value isn’t guaranteed to stay the same from one release to the next. To simplify queries, use this field.

So it feels like I'm doing the right thing, but I cant be, as zero results.

Can anyone help me understand what I'm doing wrong please?

1
  • I'm not 100% sure, but from further reading, DurableId might need to be in the format of: Contact.Billing_Contact__c.0054J000002EgGBQA0 (where '0054J000002EgGBQA0' is the UserId ) - Is that right please? I'm actually getting an error with the software im using, not a SOQL query error, have raised that with the vendor.
    – Rich
    Mar 4, 2022 at 10:32

2 Answers 2

2

Your comment is nearly there. The format for the standard object you're interested in (Contact):

  • Object API Name
    • Standard Field API Name or Custom Field Id
      • User Id

That 2nd point is the distinction. You can check the durableId for any field within the object/table you're interested in with FieldDefinition

SELECT DeveloperName, DurableId
FROM FieldDefinition 
WHERE EntityDefinitionId = 'Contact'

You would take the result from above (which would be in ObjectApiName.FieldNameOrId format) and append the UserId(s) you're interested in.

For standard fields:

SELECT DurableId,IsAccessible,IsCreatable,IsUpdatable,UserId 
FROM UserFieldAccess 
WHERE DurableId = 'Contact.Name.005XXXXXXXXXXXX'

For custom field:

SELECT DurableId,IsAccessible,IsCreatable,IsUpdatable,UserId 
FROM UserFieldAccess 
WHERE DurableId = 'Contact.00NXXXXXXXXXXXX.005XXXXXXXXXXXX'
3
  • Ah right, thank you for showing how to do both standard and custom fields, i.e. for Custom fields use the id or the field name (i.e. api name without the __c). Really helpful, thank you for your help.
    – Rich
    Mar 4, 2022 at 17:07
  • + Yes, I've now got this query (custom fields only): SELECT DurableId,EntityDefinitionId,FieldDefinitionId,Id,IsAccessible,IsCreatable,IsUpdatable,UserId FROM UserFieldAccess where DurableId IN ('Contact.00Nw0000003fCQgEAM.0054J000002EgGB','Contact.00Nw0000003fCQhEAM.0054J000002EgGB', but getting UNKNOWN_EXCEPTION error, but at least I know the SOQL is right now.
    – Rich
    Mar 4, 2022 at 17:10
  • Do you get the same error when using the ReST Tooling API, or only when querying the table from Apex? I have had more consistent results using the ReST API Mar 11, 2022 at 22:45
1

The other solution makes mention of using

  • Object API Name
    • Standard Field API Name or Custom Field Id
      • User Id

That works for standard objects, like the one in the original question, but not custom objects. I would like to point out that the formula for the DurableId on the UserFieldAccess table is:

Field Durable ID + '.' + User Id.

The Durable ID for a custom object will not be its QualifiedApiName, but instead an Id starting with 01I, similar to the way the Custom Field is working. So it will look something like this: 01I1k000001pgWQ.00N1k00000HoDmf.

If you want to create a DurableId for the UserFieldAccess table, you only need the DurableId from the FieldDefinition table for a field, and the Id for a User. Then you combine them with a period.

1
  • 1
    I'm not sure I understand the downvote on my answer (for answering the scope of the question) - but, fair play. Take an upvote and I'll update mine to be more specific Mar 11, 2022 at 23:08

You must log in to answer this question.

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