2

We have 2 custom buttons on a standard lead detailed page. I would like to show one button and hide another button on page load using javascript by querying the lead and finding a value in one text box field. The logic is if the textbox value is null, we want to show one custom button which has its own javascript code, else we will hide the custom buttton and show another one with its own javascript code. Is this possible and if so how do we do this? Buyan

3 Answers 3

2

You might be able to do this with a sidebar JS hack, but that's not my realm of expertise.

Declaratively, you could have the null/non-null values of the text field trigger workflow that changes the Lead Record Type and assign different page layouts to the two record types that are identical except for their respective buttons.

1
  • @willard I like your solution. Are you saying embed a visual force page in one of the detailed page sections and have a javascript to hide and show the buttons? I know the record type is a clean solution but we did not want to create record types and page layouts just to enable and disable buttons which is unwanted maintenance. Commented Feb 6, 2014 at 11:54
2

You can create a VF page that has some custom javascript at the top of it. This is much better than the sidebar hack imo, since the JS only gets loaded on the lead page.

A snippet of something you might do:

<apex:page standardController="Lead">
    <c:jQuery jqueryVersion="1.7.2"/>
    <script type="text/javascript">
        /* <![CDATA[ */
        // Please use jquery or some other js library you are comfortable with
        $j(document).ready(function() {
            if ({!hideButtonOne}) {
                $j("#idOfButtonOne").hide();
            } else {
                $j("#idOfButtonTwo").hide();
            }
        });
        /* ]]> */
    </script>

    <apex:detail />
</apex:page>
1
  • @buyankumar, this page would OVERRIDE your existing standard view page. Using the <apex:detail/> tag will just output the correct page layout, just like it would via a regular page.
    – willard
    Commented Feb 6, 2014 at 14:41
1

One option is to use a workflow field update to update the record type on the lead object. You could then use page layout assignments to show or hide the button.

This wouldn't be as dynamic as your thinking with JavaScript, but would be much simpler to implement.

1
  • 1
    I type too slow! :-( Commented Feb 6, 2014 at 1:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .