Sunday, December 23, 2012

Hiding a standard button on page layout


In this below example, let's say we want to hide the "save & new" button on case edit page layout.

Steps to accomplish this :-

  1. Create a html area type component on home page. Name it like admin toolbox.
  2. Keep the component position as Narrow Left column and in the body click on show html.
  3. Put the below Javascript in the body and save the component.To find the name of button, you can use firebug on firefox or console on any other browser.In this example it is "save_new".


< !--------Wait for the loading of the page--------->
<script type = "text/javascript" > 
  function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
 }
 addLoadEvent(function() {checkCasePage();}); 
</script> 
<!--------/Wait for the loading of the page---------> 

<!--------Case Button hide--------->
 <script type = "text/javascript" > 
  function checkCasePage() {
    var currentURL = window.location.href;
    
    if (currentURL.indexOf('/500') != -1) {
        if (document.getElementsByName("save_new")[0] != null)
            document.getElementsByName("save_new")[0].style.display = 'none';
        if (document.getElementsByName("save_new")[1] != null)
            document.getElementsByName("save_new")[1].style.display = 'none';
    }
 }
</script> 
<!--------/Case Button hide--------->

Now we can add this component to all our home page layouts and see the magic !

chatter community landing page


The challenge is to have our custom login page for customers/partner on chatter community to maintain our company branding.

Steps to accomplish this:-


  1. We should have force.com site enabled for chatter community. 
  2. Then we need to do few changes in "communitieslandingcontroller" method as below to get our custom visualforce page as default landing page.Here "communitieslandingcontroller" is added to our org when we enable community. "Welcome" is our custom visualforce page with login form to community.We need to enable "welcome" page for the site as well.
         public PageReference forwardToStartPage() { 
                 Pagereference pa=new Pagereference('/welcome');
                 if(UserInfo.getUserType()=='Guest'){
                    return pa; 
                 }else{ 
                    return Network.communitiesLanding(); 
                 } 
            } 

So now when we enter <base url>/community name, we get our custom visualforce page instead of standard login page and from here we can login to communities.