+ Start a Discussion
Andrea SloanAndrea Sloan 

Hiding part of a table for specific users

Part of my information within my Visualforce page applies to a subset of users and the other part applies to all users. I'm trying to avoid having to create two VisualForce pages where I would provide access to some users to one VisualForce page and access to the other users to the second page seeing that part of my VF table applies to all users. Can specific permissions be applies to one table for a specific Public Group of users and the other table to another Public Group? If so, what would the coding be and where within my table would I put it in?
Best Answer chosen by Andrea Sloan
GauravGargGauravGarg
Hi Andrea,

Please copy the below code into your controller class, that should work.
 
Public Class groupController{
	Public Boolean groupShow1{get;set;}
	Public Boolean groupShow2{get;set;}
	public groupController(){
		groupShow1 = false;
		groupShow2 = false;
		for(Group g: [Select name,DeveloperName from Group where id In (select groupId from GroupMember where UserOrGroupId =: userInfo.getuserId())]){
			if(g.DeveloperName == 'Account_Owner_SourceMarket_Team_Member')
				groupShow1 = true;
			if(g.DeveloperName == 'Non_Account_Owners_Local_DMCS')
				groupShow2 = true;
		}
		for(User u: [select id, TypeofBusiness__c, profile.name from User where id = :userInfo.getuserId()]){
			if(u.TypeofBusiness__c == 'Local DMC')
				groupShow2 = true;
			if(u.profile.name == 'System Administrator'){
				groupShow2 = true;
				groupShow1 = true;
			}
		}
	}
	
}


Hope this helps !!!

Thanks,

Gaurav

All Answers

Harish RamachandruniHarish Ramachandruni
Hi ,

Create one field in user it's check box .

query field from user to apex class getuserid()

user u =  [select  activetablefield from uder whare id= : getuserid()]

Render u.activetableapi = true ;



Regards,
HArish.R.

 
Andrea SloanAndrea Sloan
Thank you Karthik and Harish. The set of users who would would want to have access to my VisualForce page is dependent as to whether they form part of a specific Public group. My actual Public group users is populated based on a Process Builder rule determined by my user fields. However, to grant this permission, I need to base it not on a specific user's ID but moreso as to whether or not this user falls under a specific Public group. So all the users who are part of public Group A get to see table ABC and if they are part of Public group B they get to see table B and if they are part of both groups then they get to see both tables within the VisualForce page. But I cannot base it on a userID as users come and go and it would be too much maintenance. Can you redo do the coding based on what I'm describing?
Andrea SloanAndrea Sloan
Hi Karthik:
I'm sorry but your code is completely foreign to me. I'm a salesforce adminstrator and don't know any of these development terms. I don't know which are the generic words you put in and what I should replace them with. For example, you put in the word "object" but I'm dealing  with a form where data entered in my form populates into a report so it has nothing to do with objects. Allso don't know what "Alise" is or Groupshow. Is there a way I may be able to speak with you? Do you have a Skype access that perhaps I could share my screen with you and show you the code I have? I don't know how to set up a controller and call it from my VF page. I'm sure what I need to do may not be much but I'm lost in the order of this and the syntax.
Andrea SloanAndrea Sloan
What is your Skype name as I can't find you by ID? I found Kartikeyan Rajamony and sent an invite but not sure if that one is you
 
Andrea SloanAndrea Sloan
Isent you a cotnact request. Did you get it?
 
Harish RamachandruniHarish Ramachandruni
Hi,

You can go for create filrd in user object it is best way or cretaecustom setting object in your org .


And how many tables you have now and how many users is having to acess this page .


Regards ,
Harish.R
Harish.rao.salesforce@gmail.com
Andrea SloanAndrea Sloan
Harish:
As I said,  the permission must based as to whether or not users belong to a psecific Public Group. I cannot tag the permission at the user level and have to do this each time I get a new user as I already ahve a rule that determines this by placing the correct users to a specific public group when I sign them up. There could be 10-15 users needing access to one table and 20 or so to another and 10 or so needing access toboth. But since what I need is based on whether they belongto a Public group then it really doesn't matter how many users there are. I'm not doing this at the user level. It's way too much maintenance.
How were you thinking of doing this as a custom table? I've never done this and would need an example.
Andrea SloanAndrea Sloan
Hi Karthik,
i wasn't able to find you as active on Skype to send you a Contact invite. Maybe you coudl try adding me in. My ID is : ASloan@abercrombiekent.com

thank you!
GauravGargGauravGarg
Hi Andrea,

Please copy the below code into your controller class, that should work.
 
Public Class groupController{
	Public Boolean groupShow1{get;set;}
	Public Boolean groupShow2{get;set;}
	public groupController(){
		groupShow1 = false;
		groupShow2 = false;
		for(Group g: [Select name,DeveloperName from Group where id In (select groupId from GroupMember where UserOrGroupId =: userInfo.getuserId())]){
			if(g.DeveloperName == 'Account_Owner_SourceMarket_Team_Member')
				groupShow1 = true;
			if(g.DeveloperName == 'Non_Account_Owners_Local_DMCS')
				groupShow2 = true;
		}
		for(User u: [select id, TypeofBusiness__c, profile.name from User where id = :userInfo.getuserId()]){
			if(u.TypeofBusiness__c == 'Local DMC')
				groupShow2 = true;
			if(u.profile.name == 'System Administrator'){
				groupShow2 = true;
				groupShow1 = true;
			}
		}
	}
	
}


Hope this helps !!!

Thanks,

Gaurav

This was selected as the best answer
Andrea SloanAndrea Sloan
This definitely works! the correct usrs, can view the correct tables and the system admin profile gets to see everything! Thank you very much, Gaurav for all your help with this!!!!