+ Start a Discussion
ehartyeehartye 

Best practices question - Controlling visibility based on profile when page is overridden

Currently, I have the default Case pages overridden. I have users that fall into a few different categories that all need to be able to create or manage cases.

 

1. Internal users in role abc.

2. Internal users in role xyz.

3. 3rd party contractors. 

4. Customer Portal users. 

 

And the list keeps growing, and growing.

 

Currently, the way I deal with this is to use one page as the overriding page, and within the page have code like this:

 

<apex:include pageName="pageNameabc" rendered="{!$user.ProfileId == 'abc123'}">

 

<apex:include pageName="pageNamexyz" rendered="{!$user.ProfileId == 'xyz123'}">

 I am not a fan of this implementation. Hard coding Id's is not ideal, but I've not found a better way to achieve what I need.

 
Message Edited by ehartye on 11-24-2009 08:49 AM
gm_sfdc_powerdegm_sfdc_powerde
Have you considered using a single page with apex:inputField and apex:outputField for your case attributes? Visualforce respects field level security (FLS) for your profiles and automatically enforces it while rendering the page.
rubixtiousrubixtious
 

 

Why not have some booleans in your controller to set visibility, so you could then refer to them in your page.  At least you would not be hardcoding IDs.

 

Page:

 

<apex:include pageName="pageNameabc" rendered="{!isCustomPortalProfile}"> <apex:include pageName="pageNamexyz" rendered="{!NOT(isCustomPortalProfile)}">

 

Controller:

 

public String userProfile{get;set;} public Profile profile; this.profile = [Select p.Name From Profile p where p.Id = :UserInfo.getProfileId()]; if(profile != null) userProfile = profile.Name; if(userProfile == 'Customer Portal Manager') { isCustomPortalProfile = true; } else{ isCustomPortalProfile = false; }

 

CTU007CTU007

I have overridden the opportunity view page with a tabbed view, and I am hardcoding tabs' visibility

based on user's profile.

 

I think we can create a custom picklist field in user record, like casepagelayout (pagenameabc, pagenamexyz), and then in the VF page:

 

<apex:include pageName="pageNameabc" rendered="{!$user.casepagelayout == 'pagenameabc'}"> <apex:include pageName="pageNamexyz" rendered="{!$user.casepagelayout == 'pagenamexyz'}">

 

 

 

bryan.gilbertbryan.gilbert

Have you considered 

 

rendered="{!$ObjectType.Case.updateable}" 
or
rendered="{!$ObjectType.Case.accessible}" 
The global variable $ObjectType gives you access to all standard and custom objects in your system. From these you can drill down further to the field level (e.g. $ObjectType.Case.CaseNumber) and get information about the field.
Visualforce page objects have an attribute "rendered" which controls the display of the object.