Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have a custom page that overrides the default account page, dividing it into multiple tabs. I was wondering if there was a way to use the "rendered="{!IF($.........." to make the tab available to certain public groups.

I think I may need to use a controller extension buy I am not sure.

Any help is appreciated.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

In order to use a rendered formula without Apex you would need to have the data you want accessible from either one of two places.

  • A global variable.
  • Standard Controller.

Public Group Problems

Which public groups a user is a member of is not accessible from either of these.

Even with Apex, public groups pose a problem. The difficulty is that my association as a user with a public group can either be direct (I'm a user directly assigned to a group) or indirect. Indirect is the problem because I might be a member of this group because I'm in a role, role and subordinates, or another public group that is associated with this group. Even worse is that I might be a member of a group that is associated with this group through another group. It gets very messy.

You could try to enforce a policy that users are only ever directly associated with that group, but unless an admin is watching hawkishly over this group, it will always be very unpredictable. But even then, this isn't really what public groups are intended to be used for, so you might consider another option.

Option 1: Try a Custom User Field

I would suggest using some other means of testing which users are allowed to see these tabs. Custom field in User is a time-tested option. In this case the option of the global variable does open itself back up to you. If you make it a checkbox, you could add the field Show_Nifty_Tabs__c to the user object. Go to each user who needs to have this setting. Then in your rendered attribute do this:

rendered="{!$User.Show_Nifty_Tabs__c}"

Yes it is a pain to maintain, but get your data loader of choice out, create a batch that you can use to easily maintain which users to add and delete, and you're settled.

Option 2: Other Global Variable Options

Alternatively, you could drive visibility off of profile or role, which also are accessible by name via a global variable. The downside with these obviously is that you membership in these must directly coincide with who gets to see the tabs, and each user only gets one profile and one role. Still, you could do multiple roles:

rendered="{!$UserRole.Name='This Role' || $UserRole.Name='That Role'}"

Option 3: Custom Setting and Apex

If you really want something custom, and you are willing to write Apex, and you absolutely don't want to have to deal with data management on individual user records, I'd look to a List Custom Setting. In the custom setting, you could manually place a comma delimited list of user record Id's, read them into a Set with Apex, and then use a custom controller with your page to test the condition that the current user Id is in the custom setting's comma delimited list.

Downside here is custom settings don't store long text, so you're limited to 14 users per setting entry before you have to add a new record in that custom setting. If you had thousands of users, this would also get messy quickly! But let's say you don't.

Once you populated the setting, you'd add an Apex class with a method that checked if the current user is in the list of user Ids:

public class MyCtrl{

    public Boolean getIsTabUser(){    

        Map<String,TabUsers__c> tabUsers = TabUsers__c.getAll();
        Set<String> tabUserIdSet = new Set<String>();

        System.debug(tabUsers);

        for (TabUsers__c tu : tabUsers.values()){
            tabUserIdSet.addAll(tu.Users__c.split(','));
        }
        return tabUserIdSet.contains(UserInfo.getUserId());

    }
}

Then in your Visualforce rendered attribute you would do this:

rendered="{!IsTabUser}"
share|improve this answer
    
Thanks a lot Peter, will probably try the custom user field, new to apex so not that confident with custom classes yet. –  user2281 Jan 24 '13 at 15:57
    
You're welcome. Good luck! –  Peter Jan 24 '13 at 16:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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