- October 3, 2018 at 12:24 pm #42897Prachi #6
Can I find out if the current user has access to a record without querying?
Can I find out if the current user has access to a record without querying?October 3, 2018 at 12:26 pm #42899chanchal kumar #13
To find out if a particular user has Edit access to a record, use the UserRecordAccess object. This object is available in API version 24.0 and later. You can use SOQL to query this object to find out if the user has edit access to the record in question.
SELECT RecordId, HasEditAccess FROM UserRecordAccess WHERE UserId = [single ID] AND RecordId = [single ID]
If you want to check a batch of records you can use
SELECT RecordId FROM UserRecordAccess WHERE UserId=:UserInfo.getUserId()
AND HasReadAccess = true ANDRecordId IN :allRecordIds LIMIT 200
But make sure that allRecordIds is a LIST of IDs. It doesn’t work if allRecordIds is a SET of IDs. I guess that’s a bug.
Also, only a maximum amount of 200 recordIds can be checked in one query.
Please Register to reply to this topic. /