+ Start a Discussion
ManjusrinuManjusrinu 

Restricting user for vf pages accessibility

Hi ,

I have a senario in which 2 users are in same profile,I have enabled one visual force page in the profile level

My second user should not have the access permision in-order to view the vf page  where as my first user can have the permission to view the vf page.
If my second user clicks on preview an error message should be shown him(You have no access to view the page)

Can anyone suggest me to solve the problem without using permission sets ??

Malika Pathak 9Malika Pathak 9

Hi MEKA,
 
If your requirement is to display certain sections of the vf page only to certain profiles then follow the following approach:
 
1. Your section should have a render attribute (which will be bound to a boolean variable)
2. Change the value of this boolean in the controller depending on the logged in a users profile
 
 

public String u {get; set;}
u = Userinfo.getUserId();
get the profile name using query something like below:
String profile = [select profilename from profile where user where id=:u];
 

once you get the profile depending on your req change the boolean variable to display/not display the sections on vf page

If you find this helpfull then mark it as the best answer.
 

Malni Chandrasekaran 2Malni Chandrasekaran 2
Hi Meka,
Have you tried with permission set? I dont think we can restrict access with Permission set. The workaround could be, remove access to the VF page at profile level and add a permission set to the user who needs access to the VF page.

Hope it helps!