function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
David JorjaniDavid Jorjani 

How to find the pages a user has access to in apex?

I want to know what pages the current user has access to using apex and run a code dynamically to show a list of those pages on a visualforce page. I have found setupentityaccess but it works with permission sets and not profiles. I only use profiles at this point. Please let me know if there is a way to do this.
PmathurPmathur
Yes here is the way to do the same but trough UserId.

First fetch all the VF pages through select query and make a set of Vf page id set. Select query will be :

[Select id from ApexPage]

After fetch all the Users having Profile which you are refering and make a userId set. Query like :
[Select id from User wnere Profile.Name='Profile Name']

After that do select query on "UserRecordAccess". Like :
[SELECT RecordId, HasEditAccess FROM UserRecordAccess WHERE UserId in: userIdSet AND RecordId in: vfPageIdSet]

It will give you all the Vf pages that Have access to that profile.

Thanks