1

I am having a dynamic button on home page side bar problem. I am not much into Jscript and Jquery so any help would be appreciated. I have a button which needs to be displayed only to few users based on certain criteria. I have pasted the code below this is happening because of the SFDC getting away with HTML home page components.

Error i am getting is - If you see this, something is broke with Dynamic Button functionality. and the button is visible to all user.


If you see this, something is broke with Dynamic Button functionality.





    /*Immediately create a unique alias for this version of jQuery to prevent conflicts with other js libraries*/
    var j$ = jQuery.noConflict();

    /*Determine what type of object is currently being displayed on the page. Only confident way to do this is get object prefix */
    var objectPefix = window.location.href.substring( window.location.href.indexOf('.com/') + 5, window.location.href.indexOf('.com/') + 8 );

    /*Determine object ID this is being submitted for. */
    var objectID = window.location.href.substring( window.location.href.indexOf('.com/') + 5, window.location.href.indexOf('.com/') + 23 );

    /*if this is an Lead fetch the Lead HeadTeam_Approval_Status__c and only show buttons for opps that are not 'In Progress' */
    var showButton = true;
    if(opjectPrefix = '00Q'){
        var oppStatus = sforce.connection.query("Select HeadTeam_Approval_Status__c from Lead where id = '" + objectID + "'");
        var oppRecords = oppStatus.getArray("records");

        if(oppRecords.length > 0){

            if(oppRecords[0].HeadTeam_Approval_Status__c == 'In Progress'){
                showButton = false;
            }
        }
    }


    /*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, User__c from Dynamic_Button__c where Object_Prefix__c = '" + objectPefix + "'");
    var records = result.getArray("records");

    /*get the current user object to use later*/
    var user = sforce.connection.getUserInfo();
    var userId = user.userId;

    /*Execute this code block once page DOM has fully loaded*/
    j$(document).ready(function(){

        /*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*/
        j$("#sidebarComponentLocator").closest(".sidebarModule").hide().prev().hide(); 

        /*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 i = 0; i


1
  • Can you please check this if condition if(opjectPrefix = '00Q'){ . I think it should be == instead of =.
    – Saroj Bera
    Commented Jul 13, 2015 at 7:36

1 Answer 1

1

As of Summer '15 this sort of JavaScript code in the sidebar will not work because Salesforce are intentionally blocking it. In the very short-term there is one work-around remaining mentioned in the answer to End of javascript sidebar workarounds? (Salesforce Classic / Aloha). But that may be removed too in Winter '16 and if it is this sort of functionality just won't be possible.

(Perhaps a reason they are doing this is that such logic usually relies on CSS class names such as sidebarModule. As these have never been part of a public API, writing code that relies on them is a "hack". And Salesforce will presumably be moving the UI over to Lightning Components in the future which will involve a lot of change.)

You must log in to answer this question.

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