0

I'm wondering if it's possible to render fields based on if the user viewing a specific page has access to view those records?

For example, I'm loading a list (looping over an object) and it loads each record from the object. All of the records appear, but if this user clicks on some of them they get a "user does not have access to view this page" error. I would like to simply filter these out if they don't have access to those specific ones.

I did a lot of this on the server side with Apex, but was wondering if there was a simpler was using conditionals in Visualforce.

1 Answer 1

2

You can use the UserRecordAccess table to query this information:

Map<Id, Boolean> isReadable = new Map<Id, Boolean>();
for (UserRecordAccess access : [
    SELECT RecordId, HasReadAccess FROM UserRecordAccess
    WHERE UserId = :UserInfo.getUserId()
    AND RecordId IN :recordIds
]) isReadable.put(access.RecordId, access.HasReadAccess);

Then, in your markup:

rendered="{!isReadable[recordId]}"

You must log in to answer this question.

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