Activity Forums Salesforce® Discussions Can I find out if the current user has access to a record without querying?

  • Anurag

    Member
    August 16, 2018 at 1:17 pm

    Hi Madhulika,

    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.

  • Prachi

    Member
    August 16, 2018 at 1:22 pm

    hi madhulika,
    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 AND RecordId 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.

    thanks.

  • shariq

    Member
    September 17, 2018 at 11:11 pm

    Hi,

    The solution that was released in Spring ’11 (version 24.0) solves for this in a very elegant way. Salesforce implemented a read-only object that you can use to query whether a user has access to a record. The object is appropriately called UserRecordAccess and provides a comprehensive summary of a user’s given access to a particular record. Because it is an object that is designed to be queried, it is very simple to plugin the user’s id and a record id (or set of record ids) and get a result.

    Hope this helps.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos