0

Anyone knows how to check in apex if the user has access to the 'OwnerId' field of any selected object. The user could be any and not only a logged-in user.

  • 2
    What have you tried? Where are you stuck? Please see How to Ask and make an edit to add any information. – David Reed Jun 22 at 14:42
  • Adding more information about your overall objective may also help. This is an unusual objective that may be an x-y problem, if what you're really wanting is, for example, the ability to transfer a record. – David Reed Jun 22 at 15:52
0

You should query on UserFieldAccess

Obtain the Id of the user regardless if he is logged-in or not. Obtain the DurableId first

SELECT Durableid FROM UserFieldAccess WHERE FieldDefinition.EntityDefinition.QualifiedApiName='Account'
        AND FieldDefinition.QualifiedApiName='Name'
        AND User.Id='<userId for the user you want to check field access for>'

Use the unique DurableId returned above to query UserFieldAccess.

SELECT DurableId,EntityDefinitionId,FieldDefinitionId,Id,IsAccessible,IsCreatable,IsUpdatable,UserId FROM UserFieldAccess WHERE DurableId = '<DurableId returned in query 1>'

Replace Account Name with OwnerId or any other field that you want to check the access for

| improve this answer | |
  • 1
    This solution doesn't work. Running the query for any user, including my self, via apex seems to return an internal server error List<UserFieldAccess> ufas = [SELECT IsAccessible FROM UserFieldAccess WHERE FieldDefinition.EntityDefinition.QualifiedApiName='Account' AND FieldDefinition.QualifiedApiName='Name' AND UserId = :userInfo.getuserId()]; – gNerb Jun 22 at 15:05
  • Not to mention that the documentation that you linked to explicity says "Represents the access that the current user has to a field" – gNerb Jun 22 at 15:10
0

You could query the User Profile and the assigned Permission sets and search for the highest permission on the Owner field.

| improve this answer | |
  • Welcome to the community, can you provide an example in code of the solution you propose? Have you tested the solution to see if it actually works? – gNerb Jun 22 at 14:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.