I'm building a Communities site with several custom objects that Communities users should access through Visualforce pages. All other Salesforce users should access these objects through the standard Salesforce pages: record list, record detail ("view"), record new/edit.
Seems like the easiest way to handle this would be to override the list, detail, and new/edit pages for these objects with the Visualforce pages, and use the apex:page action parameter to redirect all non-communities users to the standard Salesforce pages, but it doesn't look like you can detect whether the current user is a Communities user in Visualforce. (I need to detect userType, and it doesn't look like I can do so with the global $User variable.)
I could detect the user type using a controller extension...
// set containing the three Communities user types
private set<String> Communities_user_types = new set<String>{'CspLitePortal','CustomerSuccess','PowerCustomerSuccess'};
private final ApexPages.StandardController ctrl;
public Redirect_Ext(ApexPages.StandardController stdController) {
this.ctrl = stdController;
}
private final string theUserType = UserInfo.getUserType();
public void isCommunitiesUser(){ // This would be changed to a pageReference, of course.
if(Communities_user_types.contains(theUserType)){
system.debug('******** True');
} else {
system.debug('******** False');
}
}
...and then redirect non-communities users to the appropriate standard (non-overridden) page. The problem there is that, as far as I can tell, I'm stuck creating a different extension for every page!
- Object_1 list view page
- Object_1 detail page
- Object_1 new/edit page
- Object_2 ...
...and so on. If I could pass the object prefix or record ID, and an indicator telling the extension which page type (list, detail, new/edit) it was being called from, then I could write a nicely abstracted extension and use it to return the correct URL, but I don't see a way of making that work.
Another option would be to code the URL for the standard page (including nooverride=1 in the querystring) into the page action of each visualforce page, and just use a method in the extension to return true if the page should redirect: Something like, "if isCommunitiesUser == true, set the action to redirect; otherwise, set the action to null." But I can't find a way of using the return value from a method in visualforce logic.
Does anyone have any other ideas, or see something that I'm overlooking?
Thanks in advance!
Shane