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
Eager-2-LearnEager-2-Learn 

Show/Hide a button on a standard page

Hi,
I found the same question that was posted back in 2007; however, there was no answer to the question so I decided to ask again.

Is there a way to hide or show custom button on a standard page based on a condition.  In my case I want the button only to show if a system administrator is logged in, all other users should not see this button as it would be used to do some adminstrative work  such as call a VF page/controller.


Starz26Starz26
Sure...

You create a page layout for the users and one for the system admins.

You remove the button from the page layout for the users.

You show the appropriate page layouts to the appropriate profiles via page layout assignment
Eager-2-LearnEager-2-Learn
Ya, I was trying to stay away from multiple page maintenance! I was hoping that there was some kind of special override that could use javascript in the button as it was being render could check for user profile and hide or show based on that.  Maybe sometime in a future release! :)  Thank you

KodiKodi
HI,

There is a method available to accomplish what you want.  "UserInfo.getProfileId()" you can use this method into your constructor and you have to check the user's profile(whether it is admin or not).

For more info pls refer the below example.

Example:

string pf=UserInfo.getProfileId();
Profile p=[select Name from Profile where Id =:pf limit 1];
if(p.Name=='System Administrator')
{
// using rendered to show/hide button
}
Eager-2-LearnEager-2-Learn
Kodi,

Your suggestion looks like it is apex code that would be in a controller connected to a VF page; however, I am asking about a custom button on a standard page.  Or am I just not understanding your suggestion and if so please provide me more feedback?  I want to hide a button on a standard page.  If that is not possible then I may have to settle for Starz26 suggestion as I don't think the users would want to see a button on their page that is really an administrator's button.