If you want to check via Apex
which pages the running user can access, you just need to hit up a few configuration objects:
Set<Id> assigned = new Map<Id, PermissionSet>([
SELECT Id FROM PermissionSet WHERE Id IN (
SELECT PermissionSetId FROM PermissionSetAssignment
WHERE AssigneeId = :UserInfo.getUserId()
)
]).keySet();
for (ApexPage page : [
SELECT Name FROM ApexPage WHERE Name IN ('SiteLogin', 'CreateTask')
AND Id IN (
SELECT SetupEntityId FROM SetupEntityAccess
WHERE SetupEntityType = 'ApexPage'
AND ParentId IN :assigned
)
]) system.debug(page.Name);
You could store a Set<String> accessiblePages
collection and then inspect its contents to set properties like canAccessPage1
, canAccessPage2
, etc.
If you are trying to make Custom Permissions
accessible in a Visualforce Page
, the $Permission
global variable actually tells you whether or not the running user has a specific Custom Permission
assigned.
- Create a
Custom Permission
for each button you wish to control.
- Add them to
Permission Sets
as needed.
Manage Assignments
for those Permission Sets
to select which users have access.
Then your Visualforce
would look something like:
<apex:commandButton ... rendered="{!$Permission.CanAccessButton1}" />
<apex:commandButton ... rendered="{!$Permission.CanAccessButton2}" />
<apex:commandButton ... rendered="{!$Permission.CanAccessButton3}" />
Visualforce
access? Or just how to infer it to control rendering?