Search code examples
salesforcevisualforceforce.com

Hide Email on Lead Page Layout in Salesforce


I am looking at hiding Email on Leads Page Layout.

I am including it in a section already with a visualforce page but PageLayout doesn't detect that and still requires it to be on the layout.

Is there a way to remove it from the PageLayout?

I have read that you can edit a picklist but didn't find any solid examples of doing that. I also read about Field Level Accessibility but I don't think that's the way to go since everyone is part of the same role and I am only excluding the detail based off if you're the owner. I have also tried javascript but since my visualforce page is loaded in an iframe I can't access the parent document of the iframe to be able to hide or remove the value from email while viewing not as the owner.

Any thoughts would be appreciated.


Solution

  • Try hiding the field with JavaScript stored in a Custom Button. In the On-Click JavaScript for the button, you can include code that will be run on page load by jQuery that hides the Email field. You can then hide the actual button as well. Very much a hack approach, but it should work.

    Here's some code to put in the On-Click JavaScript button (modified from Daniel Llewellyn's blog post and mgsmith's force2b blog post). Hopefully this should get you jump-started. I didn't include any code on how to hide the Email field, but you said you were already trying it through your Visualforce page, so I figured I'd leave that part to you. Cheers!

    var interval;
    //The main function that does all the work
    function appendScript() {
        // Include core jQuery library by injecting it into the DOM
        var script= document.createElement('script');
        script.type= 'text/javascript';
        script.src= 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js';
        head.appendChild(script);
    
        // It takes a second to load, so put in a delay
        // (we don't want to try and reference the script
        // before it is actually loaded, so we store the interval
        // in a global variable, and set up an interval.
        // this interval dealio. This will keep running 
        // until jQuery has been found to be loaded and then
        //clears the interval so it doesn't keep running.
    
        interval=self.setInterval(function(){
    
            //Check to see if jQuery has loaded                           
            if(jQuery) {
                //if jQuery has loaded, clear the interval
                window.clearInterval(interval);
    
                // Hide the Email field
    
                // Hide the custom button
                var btnName = 'buttonName';
                try{
                    var buttons = parent.document.getElementsByName(btnName);
                    for (var i=0; i < buttons.length; i++) {
                        buttons[i].className="btnDisabled ";
                        buttons[i].disabled=true;
                        buttons[i].type='hidden';
                    }
                } catch(e) {
                    // var ee = e.message || 0; alert('Error: \n\n'+e+'\n'+ee);
                 }
            }
        }, 300);    
    }
    
    appendScript();