function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ryepesryepes 

Visualforce button

How can i restrict who see's the visualforce button ?  not using page layouts.

TejTej

can you be more specific?

 

If its a button on visual force page u can use "Rendered " Tag to dynamically render the button based on the login user profile.

ryepesryepes

currently i have a button that will update the account based on an outbound message workflow. I dont want everyone to have access to this button, but i also do not want to create another page layout just to hide this button. I was told i can code something in my visualforce page to only show this button to certain users. 

TejTej
public class my class{
 
public Boolean button { get; set; }
 
public myclass{
String profileName=[Select p.Name From Profile p where p.id=:UserInfo.getProfileId()].Name;       button = (profileName=='profile u wanna give permission')?true:false;
 
}
 
 }
in your page:
 
<apex:commandButton rendered="{!button}" value="test" action ="{!Execute}"/>
 
 
 
 

 

ryepesryepes

Would the first piece be a seperate class from the one that i already have that executes the button? or will i or can i add it to the existing?

TejTej

no need for another class

 

Add it to your existing class n try

TejTej

i have written this code as an example

 

public Boolean button { get; set; } // variable

 

String profileName=[Select p.Name From Profile p where p.id=:UserInfo.getProfileId()].Name; button = (profileName=='profile u wanna give permission')?true:false;

 

add the above two lines in your constructor