You need to sign in to do that
Don't have an account?
Soozee
Render Button based on user's public group membership
I want to render a button based on a user's public group membership.
For example, if user is member of Email Administrator public group, they should be able to see an 'Email Button' at the bottom of the page.
Here is the VF Page:
<apex:form> ... lots of other stuff... <apex:commandButton value="Email Letters" onclick="if (confirmation()) addEmailLettersJS(); return false;" rendered="{!renderButton}"/> </apex:form>
Here is the controller:
public boolean renderButton() { System.DEBUG('********* renderButton'); List<GroupMember> getGroup = [SELECT UserOrGroupId FROM GroupMember WHERE UserOrGroupId =:advid and group.name = 'EOTL - Email Admin']; //GroupMember[] getGroup=[SELECT UserOrGroupId FROM GroupMember WHERE UserOrGroupId =:advid and group.name = 'EOTL - Email Admin']; if (getGroup[0].UserOrGroupId == advID){ showButton=true; }else{ showButton=false; } System.DEBUG('********* value of show button = '+showButton); return showButton; }
The {!renderButton} on the page ALWAYS returns false, even when the user is in the group.
Also, the debug never writes the console.
Help!?!
Ok - I was able to resolve this.
Instead of calling the !renderButton function in the controller, I moved the query into the constructor like this:
And then referenced the showButton variable on the VF page, like this:
Thanks!
Suzie
All Answers
Is your user a direct member of the group, or in a subgroup that is included?
Also, how is advId determined?
Hi -
Member is a direct member of the group.
and
advID = UserInfo.getUserId();
Thank you!
Hmm. That sounds correct. Have you tried running this in the developer console with a hardcoded id to verify the query?
Hi - I ran it in Force.com Explorer. It returns the ID of the user if the user is a member.
Hi - It seems as though the !renderButton method/function is not running. Do I need to reference it somewhere else to force it to run when the page loads?
Ok - I was able to resolve this.
Instead of calling the !renderButton function in the controller, I moved the query into the constructor like this:
And then referenced the showButton variable on the VF page, like this:
Thanks!
Suzie