I was following Tehnrd's tutorial (http://www.tehnrd.com/show-and-hide-buttons-on-page-layouts/) on how to conditionally hide/show custom buttons on a page layout. I think Tehnrd's code deals with just fields that are text base, however, I want to use a checkbox field for the condition. I have put "false" in the field value and the button was hidden from the page as expected, but when I flipped it to true, the button did not appear. I tried creating this jquery code in the html area component, but that did not have success either. Do I have to change the j$().text to fit with a checkbox?

<!-- Import jQuery from google CDN, could also be static resource--><script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><script type="text/javascript">
var j$ = jQuery.noConflict();

var objectPefix = window.location.href.substring( window.location.href.indexOf('.com/') + 5, window.location.href.indexOf('.com/') + 8 );

/*Query the records from Dynamic_Button__c object as soon as possible, don't wait for DOM ready event*/
var result = sforce.connection.query("Select Button_Name__c, Field_Id__c, Field_Value__c from Dynamic_Button__c where Object_Prefix__c = '" + objectPefix + "'");
var records = result.getArray("records");

/*Execute this code block once page DOM has fully loaded*/
    /*Hide the sidebar last as this is lowest priority. First priority is show/hiding the buttons.
    Find the sidebarComponentLocator, then find parent div with class 'sidebarModule' and the hide it*/

    /*First loop through the dynamic button records and hide any that are on the layout. We must first hide all the buttons
    as the Dynamic Button records only contan the 'show' logic*/
    for (var quoterecordValue = j$("#00NK0000001L8ub_ileinner").children().attr('title');

    /*Hide button if Submit for Approval Field is not 'False'
    if(quoterecordValue != 'false'){

    /*Now loop through the Dynamic_Button_Records and show button if field value matches that define in record*/
    for (var i = 0; i< records.length; i++) {
        /*Get the value from the field on the page layout*/
        var quoterecordValue = j$("#00NK0000001L8ub _ileinner").children().attr('title');
        var showValue = records[i].Field_Value__c;

        /*Show the button if the value of the field on this record matchs the setting in the Dyamic_Button__c*/
        if(quoterecordValue == showValue){


1 Answer 1


Do I have to change the j$().text to fit with a checkbox?

This is correct. I went and started to look at the HTML for checkbox and saw it is in fact an image that they are using. What I suggest is to read an attribute from that image such as alt or title as you can see how the HTML looks below

<div id="00N50000003JWbq_ileinner"> <img src="/img/checkbox_checked.gif" alt="Checked" width="21" height="16" class="checkImg" id="00N50000003JWbq_chkbox" title="Checked"> </div>

This would be the javascript I would have to use to get the value "Checked" as shown below:


What I'm doing here in the javascript / jquery, is I find the section of html which is holding on the precious information I want to extract, and since it has a child record, I'm using the children() function to go a step deeper inside the html as this is nested within your div container. Lastly, I use the attr() method which allows me to call any attribute as seen above in the html image tag to retrieve a value.

Please remember to use the correct ID as this was an example from my side. Lastly, I would also recommend checking to see if your developer console / firebug / trouble shooting application tells you if you have any errors via javascript.

  • So I made the changes to the checkbox j$ that you stated above and the new code is above. However, that didn't work either. With the code I used above, it doesn't hide the button anymore. Should I revert back to the original code that Tehnrd wrote on his tutorial? If so, how would I hard code it like he states at the bottom of the code? Commented Jun 5, 2014 at 17:26
  • did you make sure to replace my id with your field id? Also are you getting any exceptions within your browser's console? I'm pretty much flying blind giving you advice when I can only make assumptions of what is going wrong.
    – Double A
    Commented Jun 5, 2014 at 19:51
  • I reverted back to the old code to see if I could try and make that work how it was originally intended. It still didn't work. In the chrome developer console the error reads: send sforce.SoapTransport.send, sforce.Connection._invoke, sforce.apex.execute, (anonymous function) --> 500 (Server Error) Commented Jun 5, 2014 at 20:17
  • Did you make the second home page component as Tehnrd described which imports salesforce javascript lib in order to make use of their library?
    – Double A
    Commented Jun 5, 2014 at 21:36
  • I did make the Dynamic Buttons Ajax Tools homepage link and put it on the narrow side bar. Commented Jun 5, 2014 at 21:46

You must log in to answer this question.

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