0

The query to the UserRecordAccess table is like this: SELECT RecordId, MaxAccessLevel, HasAllAccess, HasDeleteAccess, HasEditAccess, HasReadAccess, HasTransferAccess FROM UserRecordAccess where UserId = 'XXX' and RecordId = 'YYY'

We cannot query UserRecordAccess by its Id, we can only query it by current user Id and the target object's recordId.

I wonder if I need to query UserRecordAccess table in my LWC component, is there a way I can use wire service to get the UserRecordAccess data, I have the user Id and target object's recordId.

Seeing from here: https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_get_started_supported_objects.htm

UserRecordAccess is not in the supported object list which could be accessed by uiApi

Does it mean I have to write an apex class to get the data I want and then access it in my LWC?

1 Answer 1

0

The built-in wire service can only return values by record Id, so you'd have to already know the record Id. However, note that there's an alternative mode, where you use UserRecordAccess.SomePermission to get the current access for the current user.

SELECT UserRecordAccess.HasEditAccess FROM Lead WHERE Id = 'someId'

This should technically work even for UI API, as you're only querying a related field, not the primary object, which isn't supported.

Note that this only allows you to get the permissions for the current user for a given record.

3
  • Thank you! Do you know what field name I should use in the getRecord @wire service when I query my custom object. I tried to supply the field name as myObject.UserRecordAccess.HasEditAccess and I also tried to supply the field name as UserRecordAccess.HasEditAccess, both throw errors. UserRecordAccess and my object doesn't have parent child relationship, what would be the proper field name I should use in the api call?
    – Flower Sun
    Commented Feb 11, 2021 at 23:14
  • @FlowerSun I was certain that should have worked. I guess you'll need an Apex call after all.
    – sfdcfox
    Commented Feb 11, 2021 at 23:22
  • Just pointing out here that this does indeed work. Import: @salesforce/schema/object__c.UserRecordAccess.HasEditAccess, then include that in your fields, then access it with: wiredObject.data.fields.UserRecordAccess.value.fields.HasEditAccess. Commented Jun 15, 2021 at 20:55

You must log in to answer this question.

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