Friday, January 13, 2012

Hide/Show and place a custom button anywhere on a standard layout!


Problem:
I want to create a custom button that calls a URL/VisualForce page but I don’t want to place the button on the top of the page. Plus I also want to be able to hide/display the button only based on a certain field criteria of the record.

Solution:

Ingredients:
  1.   An image of the button.
  2.   One Formula field.
  3.  Your VisualForce page.


Steps:
  • Instead of creating a custom button through the custom button section create an image (png, jpeg..etc) of the button.
  • Upload the button image to the Static Resources section.
  • Create a formula field of type TEXT as such:

IF (put_your_condition_here, HYPERLINK("apex/put_your_visualforce_page_here", IMAGE("/resource/put_your_button_image_name_here", "Button Label name"),"_self"), NULL)

Now you can place the formula field anywhere on a standard page and hide and display the button image based on your formula field condition.

Feel free to post variations of this solution on this site.

Enjoy!