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:
- An image of the button.
- One Formula field.
- 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!
Hi Vardhan,
ReplyDeleteCan we place the Formula field in the Button section (Top of the page) in the page layout.
-Rakesh B
No, Forumula fields cannot be placed in the Standard/Custom button sections..
Deletea bit confused. we're using a standard page layout for assets. Can we dynamically display any button based on a field criteria without using any visualforce page?
ReplyDeleteThis comment has been removed by the author.
DeleteNo, you need a visualforce page to perform your business logic. i.e. what needs to happen when the button is clicked. The formula field will reference that VisualForce page. The idea is that you don't have to recreate the whole page and you have to write custom code only for the business logic that you need to perform. Hope that helps..
DeleteHi Gupta,
DeleteLittile bit confustion started i need to place one custom button on my standard layout based on field changing i need to hide and display . but my problem is I have seen this Blog and it is good
http://www.tehnrd.com/show-and-hide-buttons-on-page-layouts/ but while executing that code i am getting some script errors like: sforce is not defined. so again i have search for it and then finally came to your post..
i didnt understand how can we place visualforce in custom button section..
Please help me ..
Hi Veeru:
DeleteIf you already have the VF page ready that is calling an Apex Controller, then all you have to do is create a formula field as shown here.
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)
Very useful thanks!
ReplyDeleteWhat if I only want to show a simple text input field when a checkbox gets checked. Is there a way to do this without visualforcr?
ReplyDeleteNo. Unfortunately to hide/show an input textfield, you will have to create a custom visualforce page.
DeleteHi
ReplyDeleteVardhan Gupta,
I Have created as you mentioned,i con't move it to button please tell how to move this as button in standard layout