1

I had a requirement to display records in a pageblocktable, and if the user has the access to that record then the Record Name should be displayed as a Link(redirect to the record detail page) and if he doesn't has the access it should display as a text field.

Usually the aaproach would be to use the SObject_share to query the user's accessibility over that record, But how it would differ if we get the results using "UserRecordAccess" object to get the list of user's accessible records.

Approach for the solution was, to get all the records on a search page. Comparing the records querying SObject_Share / UserRecordAccess and mapping the same with earlier list and have a checkbox(true/false) based on the value of the checkbox Name would be displayed as Link or Text.

Can anyone tell me how much it differs querying an SObject and UserRecordAccess?

3
  • 1
    If you let your controller do the work, using "with sharing", only results the user can see should be returned. This would seem to save you a lot of headaches and unnecessary trouble.
    – crmprogdev
    Commented Mar 22, 2018 at 12:26
  • I guess that would not consider the sharing that is being done using a trigger or some other procedure - I am not sure of it. And the classes here are written with without sharing keyword and due various dependencies I cannot go with withsharing keyword. Commented Mar 23, 2018 at 9:27
  • That depends entirely on which classes calls the others & in what sequence. If a class with sharing calls a class that's without sharing, the without sharing will return all results to the calling class regardless of sharing, but the with sharing class will "filter" those results before displaying them to a user.
    – crmprogdev
    Commented Mar 23, 2018 at 13:30

1 Answer 1

7

There are several important differences between MyCustomObject__Share and UserRecordAccess sobjects:

MyCustomObject__Share

  1. If OWD for MyCustomObject__c is set to the most permissive Public Read/Write, then sobject MyCustomObject__Share will not exist in organization at all. So once your SOQL will try to select this records there will be an error that such type doesn't exist.
  2. can be inserted via Apex
  3. can be queried more then 200 records in one query, when ParentID is present

UserRecordAccess

  1. Exists with any OWD settings for sobject
  2. Is only queriable. You can’t create, delete, or update any UserRecordAccess record
  3. Up to 200 record IDs can be queried in one query, but no more
1
  • UserRecordAccess is also calculated by user's permissions, e.g. if they have Modify All Data it will show maximum access despite whatever is in the OWD and share tables.
    – sfdcfox
    Commented Mar 22, 2018 at 14:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .