Last active
December 13, 2015 20:08
-
-
Save dsharrison/b0b03c661bf65fc18348 to your computer and use it in GitHub Desktop.
Controller and visualforce page to demonstrate missing records with UserRecordAccess query.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page controller="UserRecordAccessDebugCtrl" showHeader="true" sidebar="true"> | |
<!-- | |
Load this page with a record in the 'id parameter as users with varying record access | |
--> | |
<apex:form> | |
<h2>User</h2> | |
<br /> | |
<apex:selectList value="{!userId}" size="1"> | |
<apex:selectOptions value="{!userOptions}" /> | |
<apex:actionSupport event="onchange" rerender="debug" /> | |
</apex:selectList> | |
</apex:form> | |
<br /> | |
<apex:outputPanel id="debug"> | |
<h2>Access</h2> | |
<p>{!accessDebug}</p> | |
<h2>Record</h2> | |
<p>{!recordDebug}</p> | |
</apex:outputPanel> | |
</apex:page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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