Trying to query the Lead’s Owner’s UserRecordAccess .HasReadAccess

I want to query a Lead record and find out if the Lead’s Owner has read access. I tried the following query but it fails.

select Id, Owner.UserRecordAccess.HasReadAccess from lead WHERE Id = '<myid>'

The error returned is:

Didn’t understand relationship ‘UserRecordAccess’ in field path.


You can’t use subquery to check UserRecordAccess fields value

So pass the recordId and ownerId/userId.. to check that user having what type of access on that record.. and RecordId will be lead Id/sobject id

you can check variables like HasReadAccess.

List<UserRecordAccess> lstUserRecordAccess = [SELECT RecordId,MaxAccessLevel,HasAllAccess, 
                                                FROM UserRecordAccess 
                                               WHERE UserId = 'Pass user Id' 
                                                 AND RecordId = 'Pass lead Id'];

Source : Link , Question Author : user31673 , Answer Author : Ratan Paul

Leave a Comment