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
RedSalesRedSales 

Display Custom Button In Page Layout Only When A Specific Custom Field is Populated

Hello,

 

I wish to add a custom button to one of my page layouts. However I do not want this button to always appear. I wish for it only to appear based on a status flag I will create for my object on which the button is added (via the page layout).

Is it possible when creating a custom button to somehow include an "if" statement somewhere that controls the display of the button based on the custom flag value stored in the object?

 

I'm guessing that this may not be possible without it being a visualforce page but hopefully I'm wrong.

 

Any help would be good.

 

Thanks in advance!

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Ritesh AswaneyRitesh Aswaney

Dont reckon its possible with standard salesforce.

 

Will need some visualforce, though you don't have to replace the entire page, just a VisualForce section would do, which you could overlay into the standard page layout.

 

The visibility of the button can then be controlled using the rendered attribute.

 

OR MAYBE THERE IS A WAY !  you could just render the button and then have it trigger some javascript.

 

The javascript can check the conditions under which the button should execute, if they aren't met, it could just return an error to the user.

All Answers

flewellsflewells

I'm not aware of a way to do this with custom buttons and page layouts.

 

I had a similar requirement and implemented a custom formula field as a workaround.

 

Specifically, I needed a button that would generate a document using Conga Composer (an AppExchange app offered by AppExtremes), but I didn't want all users to have access to it.  It took a bit of trial and error and help from AppExtremes (their support is great, by the way!), but I was able to create a custom formula field (text) that shows a simple text message to users who shouldn't see the button, and a button image (***) that calls Conga Composer for users who can generate these reports.  So it's a conditional formula (IF statements) with IMAGE and HYPERLINK functions used to display the "button".  I actually ended up liking this better than a custom button because I can put the custom field anywhere on the page layout and leverage field-level security too.

 

(***) this solution requires creating a picture file of a button and saving it to the Documents tab.  The IMAGE function refers to this document.

 

 

Ritesh AswaneyRitesh Aswaney

Dont reckon its possible with standard salesforce.

 

Will need some visualforce, though you don't have to replace the entire page, just a VisualForce section would do, which you could overlay into the standard page layout.

 

The visibility of the button can then be controlled using the rendered attribute.

 

OR MAYBE THERE IS A WAY !  you could just render the button and then have it trigger some javascript.

 

The javascript can check the conditions under which the button should execute, if they aren't met, it could just return an error to the user.

This was selected as the best answer
RedSalesRedSales

Hi flewells,

 

Thank you for your help. I tried to accept both answers as the solution but seems only one can be accepted at a time!

 

Thanks Again.

flewellsflewells

Glad it helped. 

 

I appreciate you trying to accept both answers as a solution.  As it looks right now though, the contriubtion from Ritesh Aswaney is marked as the solution...

GuillermoPGuillermoP

you can do this, but not as a button, you have to write up a URL hack formula. work your button out to do what you want, then convert it to a Formual field, and base it on the IF statement of the flag value being TRUE.

 

Should work like a charm.