is there a way to check if the current user has permission to edit an object (Controlled by Profile and Permission Sets).
This is my scenario:
- I have a custom LWC which pulls information from multiple objects. (For simplicity, let's assume ObjectA__c and ObjectB__c)
- Only some users (controlled by profile and permission sets) are able to create/edit these objects and their records. For example: only I can edit these records, as only I have the right profile and permission sets assigned.
- Other user's opening this component, should not be able to edit any of these fields (This will be controlled by just setting the disabled property in the lightning-input, if I know the current user has no permission to edit, then I will set the disabled property to true for all lightning-inputs)
So this is what I want to do, basically, I want to be able to check in LWC
Whether the current user have permission to edit the objects or not.
I have referred to this stack. Where I can use the UserRecordAccess object, but this will require me to input a recordId. My concern is that, what is the record is shared to this user? Also there's a limitation of only 200 recordIds. Also I tried, executing this query in anonymous apex and printed it in log, I could not seem to find the UserRecordAccess. getting logged:
SELECT Id, Name, UserRecordAccess.HasReadAccess, UserRecordAccess.HasTransferAccess, UserRecordAccess.MaxAccessLevel FROM sObjectName
Query Credits - Marco Pietersen from the same stack hyperlinked above.
Main Question:
Is there a way to only input the Object name and check whether the current user has permission to create/edit this object records or not?
Another way of doing this, is of course by letting the user's edit and then in the save logic commit the save with as user and show a toast (error) the users. While, I think it is better to stop them from editing in the first place, is a better design.
Many thanks in advance!