So it is much ideal to check what rights users has on a record rather than handling "Insufficient Access" exceptions.The access rights particular user has on a record can be obtained by UserRecordAccess standard object.
Please note : UserId and RecordId on where clause are required
SELECT RecordId, HasReadAccess, HasTransferAccess, MaxAccessLevel FROM UserRecordAccess WHERE UserId = [single ID] AND RecordId = [single ID] //or Record IN [list of IDs]
eg: check logged users permission on a record with Id "a1100000000000a"
SELECT RecordId, HasReadAccess, HasTransferAccess, MaxAccessLevel
FROM UserRecordAccess
WHERE UserId =:UserInfo.getUserId()
AND RecordId='a1100000000000a'
if your record view page is overridden with Visualforce Page and it uses custom controller or extension you can use UserRecordAccess object to show/hide buttons based on user permission.
More Details about UserRecordAccess from here
No comments:
Post a Comment