Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Controller and visualforce page to demonstrate missing records with UserRecordAccess query.
<apex:page controller="UserRecordAccessDebugCtrl" showHeader="true" sidebar="true">
Load this page with a record in the 'id parameter as users with varying record access
<br />
<apex:selectList value="{!userId}" size="1">
<apex:selectOptions value="{!userOptions}" />
<apex:actionSupport event="onchange" rerender="debug" />
<br />
<apex:outputPanel id="debug">
public without sharing class UserRecordAccessDebugCtrl {
private Id recordId {get;set;}
public Id userId {get;set;}
public List<SelectOption> userOptions {get;set;}
public UserRecordAccessDebugCtrl() {
recordId = ApexPages.currentPage().getParameters().get('id');
userOptions = new List<SelectOption>();
for(User u : [SELECT Name, Username, Profile.Name FROM User ORDER BY Name]) {
userOptions.add(new SelectOption(u.Id, u.Name + ' [' + Profile.Name + ']'));
userId = userInfo.getUserId();
public String getAccessDebug() {
return JSON.serialize(Database.query('SELECT RecordId, MaxAccessLevel FROM UserRecordAccess WHERE RecordId = :recordId AND UserId = :userId'));
public String getRecordDebug() {
return JSON.serialize(Database.query('SELECT Name, UserRecordAccess.HasEditAccess FROM Opportunity WHERE Id = :recordId'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment