loading... Salesforce Cat

Wednesday, October 8, 2014

Salesforce User Record Permission

When it comes to Salesforce what user can or can't do to a record depends on the sharing rights that particular user has on the record.For an example if user want to view a record , that record must be read shared with the user, if he want to edit a  record that record must be edit shared.One important point to note is object permission defines is what Operations are allowed for the user on a particular object on what record(s) that operation is allowed depend on the user record sharing..for a example if a user's profile has edit rights on a object doesn't mean he can edit  all the records of that object but only the records edit shared to him.

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