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
SebiSebi 

Displaying custom buttons only when criteria is met?

Is there a way to have custom buttons only appear, or even be disabled, if certain criteria is not met? For example, if Widget__c is blank or missing in an object, do not show or disable a custom button named 'Transform Widget'?

 

Any help is greatly appreciated.

flewellsflewells

Aside from using Visualforce, the only way I can think to conditionally show/hide a custom button is if you have a different page layout.  Which, assuming the same user needs to see the different page layouts will mean different record types.  Not a good way to go, in my opinion.

 

A workaround I have done is create a custom formula field of type "Text" and use the IF, HYPERLINK and IMAGE functions to show a button image to some users in certain situations and show text or nothing to other users (or other situations).  In my case, my "button" links to a report where I pass parameters from the record, or initiates a third-party application.  This workaround may or may not be an option for you, depending on what you're custom button does.

SebiSebi

Thanks for the reply. I thought of that too but I wanted the button to appear where the other detail buttons are.

incuGuSincuGuS

Obviously not the best solution ,but within the buttons code you can execute JS . If this is your case (a js button) you can add the conditional check there and execute JS to remove itself.

 

For example:

 

I want to make the Button "Check Email" on Contact appear only when the Contact has a Email value, within the code check for the value , and if you can traverse through the dom and find what you need to check, and do JS to remove the button from the dom.

 

Not exactly "neat" but not entirely "ugly" :). Hope this helps as a last resort/alternative.
Gaston.