So I have a VF page that calls some other VF pages based on a button click. The button will reroute to a different VF page depending on a value within a dropdown.
Sometimes the logged in user will not have access to the VF page. I want to hide the dropdown item if they don’t have access to it. I know you can do this with objects, via {!$ObjectType.objectname.accessible}, but can you do something similar with VF pages?
An alternative solution would be that the controller would throw an error message back to the page, but same issue applies – I still don’t know how to get the accessibility of a VF page through apex.
Answer
Profile rights can be queried although the data model is bit complex. Actual user’s permissions depend on his Profile and any Permission Sets that were assigned to him on top of the Profile.
Start by looking at the data model: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_erd_profile_permissions.htm
Your data is hidden in the SetupEntityAccess
and that help page lists some useful examples. Especially the last one looks very promising:
SELECT Id, SetupEntityId, SetupEntityType
FROM SetupEntityAccess
WHERE ParentId
IN
(SELECT PermissionSetId
FROM PermissionSetAssignment
WHERE AssigneeId = '005D0000001QOzF')
AND (SetupEntityId = '02uD0000000GIiMIAW')
Substitute the hardcoded variables with
UserInfo.getUserId()
- result of
SELECT Id FROM ApexPage WHERE Name = 'Foobar' AND NamespacePrefix = null
Attribution
Source : Link , Question Author : willard , Answer Author : eyescream