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
Scott.MScott.M 

Check if a user has access to a visualforce page

Is there a way to check if the current running user has permission to access a specific visualforce page?

kiranmutturukiranmutturu

you can't achive this at  user level....you can check with the profile... 

Scott.MScott.M

how would check if the profile has access in code?

kiran2000kiran2000

Hi Scott,

 

        Go to that visualforce page under setup-->click on security settings of that vf page -->enable the profile access for which you want to give access to vf page

Scott.MScott.M

Yes, but I want to check if the running profile has access to an unknown page before I send the user there.

 

class sudo{

 

  public pageReference myAction() {

 

      //do something

 

      if(user has access to page)

         return user_configured_page

      else

         return other_page

  }

 

 

}

kiranmutturukiranmutturu

u can check the profile check in the page level itself....

 

like {!$profile.name} == 'system admin'... then only you can process.....

Imran MohammedImran Mohammed

No, that can be found through Apex.

The only way is through what kiran has mentioned.

TryForce.ax1449TryForce.ax1449

Did anyone get the solution? please reply

arunadeveloperarunadeveloper

Hi did you get the solution to this problem i am also having same issue.

khillan bhardwajkhillan bhardwaj
Hi,

Yes we can check whether login user have access to the specific page.following is the code which show. whether login user have access to given page.

List < SetupEntityAccess> SEA =[SELECT Id, Parent.Name, Parent.Profile.Name, Parent.Profile.Id FROM SetupEntityAccess WHERE Parent.Profile.Id = :UserInfo.getProfileId() AND SetupEntityId in (SELECT Id FROM ApexPage WHERE Name = 'Given Page  name' AND NamespacePrefix = null)];
if(SEA.isEmpty()){
      //Login user do not have access to given page
}else{
     //login user have access to given page
}

Hope it will be helpful to you.

Thanks
Khillan Singh