0

I have a vf page in that i included another VF page i.e
<apex:include pageName="2nd_vfpage"/>

I want to show that "2nd vfpage" to only allowed user. How we can do this through permission set.

Thanks for your help

0

If I understand it correctly you want to show parent page to all users and included page to specific user. Currently even if user does not has permission to child page he would be able to access it since user has access to parent page. There is a solution if you want to manage access to included page by permission set. Lets consider an example. Here is my page which is available for every user.

EveryUserPage:

<apex:page controller="EveryUserController">
  <h1>This page is for every user.</h1>
   <apex:include rendered="{!hasAccessToSpecialPage}" pageName="SpecialUser"/>
</apex:page>

This page can be accessed by any user. Now you can control access to included page which by setting a boolean variable and then you can check if current user has access to the page which are going to include by below code.

EveryPageController:

public class EveryUserController {
    public Boolean hasAccessToSpecialPage {get;set;}

    public EveryUserController(){
        checkIfCurrentUserHasAccessToSpecialPage();
    }

    public void checkIfCurrentUserHasAccessToSpecialPage(){
        hasAccessToSpecialPage = true;
        try{
            PageReference pg = Page.SpecialUser;
            pg.getContent();//if user does not have access to this page then it will throw exception
        }catch(Exception ex){
            hasAccessToSpecialPage = false;
        }
    }


}

Here we are making user of getContent. Whenever a user who does not have access to page tries to call getCOntent he gets an exception. If there is exception means user has no access to the page either by profile or permission set. Based on this information you can decide when to show page and when not to.

Just posting specialUser page:

<apex:page >
  <h1>This page is visible to only speical users.</h1>
</apex:page>

Now you would be able to use permission set to manage access to speicalUser page for users to which you want to give access to. Please mark this as solution if this helps you so that others could be benefited from this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.