Sunday, 15 September 2013

Hide Recycle Bin from Home Page Layout 

 Salesforce doesn't provide specifications to remove Recycle Bin from Home Page.But there are situations which demands that the Recycle Bin shouldn't be shown over the Home Page. In such adverse situations JavaScript is our Best Friend.


First Let me tell you about this Dustbin of Salesforce.

The Recycle Bin link in the sidebar lets you view and restore recently deleted records for 15 days before they are permanently deleted.

Follow the following steps to Hide the Recycle Bin.
 

Click on Name > Setup > Customize > Home > Home Page Components.
Click on New to add a New Custom Component. 

Make sure that you have checked WIDE COMPONENT and SHOW HTML Checkbox. 

 

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
<span id="hideMyParentsp">
</span>
<script>
$(document).ready(function() {  $('#sidebarDiv #hideMyParentsp').parent().parent().hide();      });
</script>

<script type="text/javascript">
window.onload = function(){
var x=document.getElementsByTagName("img");
for(var i=0;i<x.length;i++) {
  if(x[i].title=='Recycle Bin')  {
     var dtag = x[i].parentNode.parentNode.parentNode; dtag.style.visibility='hidden';
      }
 }
var xx=document.getElementsByTagName("span");
for(var ii=0;ii<xx.length;ii++) {
  if(xx[ii].innerHTML=='Recycle Bin')  {
 xx[ii].style.display='none';
  }
 }
 };
 </script>
 
 
 

 Click on Save.

Next we need to add this component on Home Page Layout.For this Follow the following Steps
   
    Click on Name > Setup > Customize > Home > Home Page Layout.

 

Select "Edit" for your Layout from which you want to remove Recycle Bin.
    Check the Component which you just created in Wide Column Display , Click Next

 

Click Save , Additionally you can see the preview.


  You can see the changes in your Home Page. Recycle Bin is No More. You can say that his soul is with us [as it is just hidden] but his body left the mortal world. 

 

 

 

  

Sunday, 11 August 2013

Pagination using StandardSetController

I have struggled with pagination issue and finally implemented with StandardSetController.

Controller:


public with sharing class Pagination_min {

    public PageReference print() {
        pageReference pg = new PageReference('/apex/printPage');
        return pg;
    }

    Public Integer noOfRecords{get; set;}
    Public Integer size{get;set;}
    public  list<JobSuite__job__c> lstJob = new list<JobSuite__Job__c>();
    public set<Id> cmpId = new set<Id>();
    public Pagination_min()
    {
       
        lstJob = [select Name,JobSuite__JS_Client__c,JobSuite__Campaign__c from JobSuite__Job__c  ];
       
        for(JobSuite__Job__c objob: lstJob)
        {
            cmpId.add(objob.JobSuite__Campaign__c);
        }
   
    }
    public ApexPages.StandardSetController setCon {
        get{
            if(setCon == null){
                size = 1;
                string status = 'Active';
               
                //string queryString = 'Select Name from JobSuite__JOb__c where JobSuite__Status__c =:Status';
                system.debug('Ids...'+cmpId);
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id, name FROM JobSuite__Campaign__c where  Id IN:cmpId order By Name]));
                setCon.setPageSize(size);
                noOfRecords = setCon.getResultSize();
            }
            return setCon;
        }set;
    }
   
    Public List<JobSuite__Campaign__c> getAccounts(){
        List<JobSuite__Campaign__c> accList = new List<JobSuite__Campaign__c>();
        for(JobSuite__Campaign__c a : (List<JobSuite__Campaign__c>)setCon.getRecords())
            accList.add(a);
        return accList;
    }
   
    public pageReference refresh() {
        setCon = null;
        getAccounts();
        setCon.setPageNumber(1);
        return null;
    }
}



Page:




<apex:page controller="Pagination_min">
    <apex:form >
        <apex:pageBlock id="pb">
            <apex:repeat value="{!Accounts}" var="a">
                 {!a.Name}
               
                 <apex:commandbutton action="{!print}" value="Print"/>                
            </apex:repeat>
            <apex:panelGrid columns="7">
               
                <apex:commandButton status="fetchStatus" reRender="pb" value="<" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/>
               
                <apex:outputText >{!(setCon.pageNumber * size)+1-size}  of {!noOfRecords}</apex:outputText>
               
            </apex:panelGrid>
        </apex:pageBlock>
    </apex:form>
</apex:page>