function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student 

Javascript remoting - 135 KB limit, 1000 rows - Please help

Hey there, I was hoping to get a hand on how to implement javascript remoting. I have been told that it can be used to get passed the 135 kb view state limit and the 1000 row pageblocktable limit. I have a visualforce page which I have overriden my custom object tab (transactions). 

I wanted to test to see if it could handle bulk records as I am yet to release my system, on a side note i also employ Avi's pageblocktable enhancer. On first test after bulk uploading 2000 records i tried opening the tab and it only displayed 20 records, I played around wrote a custom controller (then added to it for all my overriden tabs, added read - only to the tab apex page tag, but I am still having trouble with view state.

Please, i was hoping someone could help me out by guiding me to imeplement javascript remoting, I am very lost in this and have only recently become semi decent in understand apex. Any tips on my code would also be appreciated. Thank you in advance for your help.

Page
<apex:page Controller="GlobalObject_Query"  tabStyle="Transaction__c" readOnly="true">
<apex:stylesheet value="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/ui-lightness/jquery-ui.css"/>
<script>
$j = jQuery.noConflict();
function highlightElem(elem){
$j(elem).parent().parent().parent().find('tr').removeClass('ui-state-highlight');
$j(elem).parent().parent().addClass('ui-state-highlight');
}
</script>
<c:PageBlockTableEnhancerADV targetPbTableIds="pbtTra"  pageSizeOptions="25,50,100,250,500,750" defaultPageSize="25" enableExport="False"/>
<apex:sectionheader title="Transactions" subtitle="Home"></apex:sectionheader>
 <apex:form >
  <apex:pageBlock id="pb" >
 
    <apex:pageBlockTable value="{!GlobalTransactions}" var="Tra" cellPadding="4"  border="4" id="pbtTra">
<apex:column headerValue="Transaction"  >
<apex:commandLink rerender="Tradetails" oncomplete="highlightElem(this);"> {!Tra.Name}
<apex:param name="Tid" value="{!Tra.id}"/>
</apex:commandLink>
</apex:column>
<!-- <apex:column headervalue="Account" value="{!Tra.Account__c}"/> -->
<apex:column headervalue="Date" value="{!Tra.Date_of_Payment__c}"/>
<apex:column headervalue="Amount" value="{!Tra.Amount__c}"/>
<apex:column value="{!Tra.Method__c}"/>
<!-- <apex:column headervalue="Service" value="{!Tra.Service_Name__c}"/>-->
<apex:column headervalue="Office" value="{!Tra.Office__c}"/>

    </apex:pageBlockTable>

</apex:pageBlock>
 </apex:form>
<apex:outputPanel id="Tradetails">
<apex:detail subject="{!$CurrentPage.parameters.Tid}" relatedList="True" inlineEdit="True" title="false"/>
</apex:outputPanel>
</apex:page>


class
 
public class GlobalObject_Query{


 //Introduce Objects   
 public Transaction__c       Tra    {get;set;}
 public Service__c           Ser    {get;set;}
 public Finance__c           Fin    {get;set;}
 public Property__c          Prop   {get;set;}
 public Destiny_Survey__c    Sur    {get;set;}  
 public Office_Commission__c OffCom {get;set;} 
 public Office_Invoice__c    OffInv {get;set;}
 
 //Introduce Lists
 List<Transaction__c> TransList = new List<Transaction__c>();
 List<Service__c> ServList = new List<Service__c>();
 List<Finance__c> FinList = new List<Finance__c>();
 List<Property__c> PropList = new List<Property__c>();
 List<Destiny_Survey__c > SurvList = new List<Destiny_Survey__c >();
 List<Office_Commission__c> OffComList = new List<Office_Commission__c>();
 List<Office_Invoice__c> OffInvList = new List<Office_Invoice__c>();

   
   
   //Construct Controller and set variables     
   public GlobalObject_Query() {
   //Transaction
   this.Tra = Tra;
   this.transList = new List<Transaction__c>();
   //Service
   this.Ser = Ser;
   this.ServList = new List<Service__c>();
   //Finance
   this.Fin = Fin;
   this.FinList = new List<Finance__c>();
   //Properties
   this.Prop = Prop;
   this.PropList = new List<Property__c>();
    //Surveys
   this.Sur = Sur;
   this.SurvList = new List<Destiny_Survey__c >();
   //Office Commission
   this.OffCom = OffCom;
   this.OffComList = new List<Office_Commission__c>();
   //Office Invoice
   this.OffInv = OffInv;
   this.OffInvList = new List<Office_Invoice__c>();
    }      

   //Transaction Queries              
   public List<Transaction__c> getGlobalTransactions()
    {
    
        this.transList.addAll( [SELECT ID, Name, Amount__c, Account__c, Service_Name__c, method__c, Transaction_type__c, date_of_payment__c, Office__c, createddate FROM Transaction__c LIMIT 10000]);
    
 if (this.transList == null || this.transList.isEmpty()) {
            return null;
        }

        return this.transList;
    }
    
    
   //Service Queries              
   public List<Service__c> getGlobalServices()
    {
    
        this.ServList.addAll( [SELECT ID, Name, Account__c, Service_Name__c, Service_Type__c, Start_of_Service__c, Service_Stage__c, Amount_remaining__c, Office__c FROM Service__c LIMIT 10000]);
    
 if (this.ServList == null || this.ServList.isEmpty()) {
            return null;
        }

        return this.ServList;
    }
    
       //Finance Queries              
   public List<Finance__c> getGlobalFinances()
    {
    
        this.FinList.addAll( [SELECT ID, Name, Account__c, Finance_Office__c, Finance_Writer__c, Application_Submitted__c , Application_Amount__c, Conditional_Approval__c, Unconditional_Approval__c, Amount_Approved__c, Finance_Settlement__c FROM Finance__c LIMIT 10000]);
    
 if (this.FinList == null || this.FinList.isEmpty()) {
            return null;
        }

        return this.FinList;
    }
 
 
    //Property Queries              
   public List<Property__c> getGlobalProperties()
    {
    
        this.PropList.addAll( [SELECT ID, Account__c, Name, Office__c, Property_Type__c, Property_Full_Address__c, Destiny_Finance__c FROM Property__c LIMIT 10000]);
    
 if (this.PropList == null || this.PropList.isEmpty()) {
            return null;
        }

        return this.PropList;
    }
 
 
    //Survey Queries              
   public List<Destiny_survey__c> getGlobalSurveys()
    {
    
        this.SurvList.addAll( [SELECT ID, Name, Account__c, Office__c, Survey_Type__c, How_likely_are_you_to_refer_Destiny__c FROM Destiny_survey__c LIMIT 10000]);

    
 if (this.SurvList == null || this.SurvList.isEmpty()) {
            return null;
        }

        return this.SurvList;
    }
 
 
    //Office Commission Queries              
   public List<Office_commission__c> getGlobalOfficeCommissions()
    {
    
        this.OffComList.addAll( [SELECT ID, Name, Office__c, Commission_Period_Start__c, Commission_Period_End__c, Total_Professional_Service_Fees_Due__c, Total_Finance_Commissions_Due__c FROM Office_Commission__c LIMIT 10000]);
    
 if (this.OffComList == null || this.OffComList.isEmpty()) {
            return null;
        }

        return this.OffComList;
    }
 
 
    //Office Invoice Queries              
   public List<Office_Invoice__c> getGlobalOfficeInvoices()
    {
    
        this.OffInvList.addAll( [SELECT ID, Name, Office_Invoice_Date__c, Office_Invoice_Amount__c, Office_Invoice_Description__c, Payment_Date__c, Office_Name__c, Office_Commission__c FROM Office_Invoice__c LIMIT 10000]);

 if (this.OffInvList == null || this.OffInvList.isEmpty()) {
            return null;
        }

        return this.OffInvList;
    }
 
 
}

 
Akshay DeshmukhAkshay Deshmukh
Hi,
Unfortunately i could not find blog address for you hence posting whole code.
This code is user for sorting and pagination. You can change pageSize variable to any number you want.

This code is well tested so it should guide you.

VF Page:
<apex:page controller="MyPagingController" tabStyle="Account">
   <apex:sectionHeader title="Accounts List with Paging"></apex:sectionHeader>
   <apex:form >
      <apex:pageBlock title="" id="pageBlock">
         <div align="right" style="display:{!IF(NOT(ISNULL(accounts)),'block','none')}">
            <font size="1pt">
               Page #:&nbsp;
               <apex:outputLabel value="{!PageNumber}"/>
               &nbsp;out of&nbsp;
               <apex:outputLabel value="{!totalPageNumber}"/>
               &nbsp;&nbsp;&nbsp;&nbsp;
            </font>
            <apex:commandButton value="Previous" action="{!previousBtnClick}" disabled="{!previousButtonEnabled}" reRender="pageBlock"></apex:commandButton>
            <apex:commandButton value="Next" action="{!nextBtnClick}" reRender="pageBlock" disabled="{!nextButtonDisabled}" ></apex:commandButton>
         </div>
         <br/><br/>
         <apex:pageBlockTable value="{!accounts}" var="a" rendered="{!NOT(ISNULL(accounts))}" rows="{!PageSize}">
            <apex:column >
               <apex:facet name="header">
                  <apex:commandLink action="{!ViewData}" value="Account Name{!IF(sortExpression=='name',IF(sortDirection='ASC','▼','▲'),'')}" id="cmdSort">
                     <apex:param value="name" name="column" assignTo="{!sortExpression}" ></apex:param>
                  </apex:commandLink>
               </apex:facet>
               <apex:outputLink value="/{!a.Id}" target="_blank">{!a.Name}</apex:outputLink>
            </apex:column>
            <apex:column value="{!a.Phone}">
               <apex:facet name="header">
                  <apex:commandLink action="{!ViewData}" value="Phone{!IF(sortExpression=='Phone',IF(sortDirection='ASC','▼','▲'),'')}">
                     <apex:param value="Phone" name="column" assignTo="{!sortExpression}" ></apex:param>
                  </apex:commandLink>
               </apex:facet>
            </apex:column>
            <apex:column value="{!a.BillingCity}">
               <apex:facet name="header">
                  <apex:commandLink action="{!ViewData}" value="Billing City{!IF(sortExpression=='BillingCity',IF(sortDirection='ASC','▼','▲'),'')}">
                     <apex:param value="BillingCity" name="column" assignTo="{!sortExpression}" ></apex:param>
                  </apex:commandLink>
               </apex:facet>
            </apex:column>
            <apex:column value="{!a.BillingCountry}">
               <apex:facet name="header">
                  <apex:commandLink action="{!ViewData}" value="Billing Country{!IF(sortExpression=='BillingCountry',IF(sortDirection='ASC','▼','▲'),'')}">
                     <apex:param value="BillingCountry" name="column" assignTo="{!sortExpression}" ></apex:param>
                  </apex:commandLink>
               </apex:facet>
            </apex:column>
         </apex:pageBlockTable>
         <div align="right" style="display:{!IF(NOT(ISNULL(accounts)),'block','none')}">
            <br/>
            <font size="1pt">
               Page #:&nbsp;
               <apex:outputLabel value="{!PageNumber}"/>
               &nbsp;out of&nbsp;
               <apex:outputLabel value="{!totalPageNumber}"/>
               &nbsp;&nbsp;&nbsp;&nbsp;
            </font>
            <apex:commandButton value="Previous" action="{!previousBtnClick}" disabled="{!previousButtonEnabled}" reRender="pageBlock"></apex:commandButton>
            <apex:commandButton value="Next" action="{!nextBtnClick}" reRender="pageBlock" disabled="{!nextButtonDisabled}" ></apex:commandButton>
         </div>
      </apex:pageBlock>
   </apex:form>
</apex:page>


CONTROLLER:

public class MyPagingController{     
    
    private List<Account> accounts;     
    private List<Account> pageAccounts;     
    private String sortDirection = 'ASC';     
    private String sortExp = 'name';     
    private Integer pageNumber;     
    private Integer pageSize;     
    private Integer totalPageNumber;     
    
    public Integer getPageNumber(){     
        return pageNumber;     
    }          
    public String sortExpression {        
        get{return sortExp;}      
        set{
            if (value == sortExp)        
                sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';      
            else
                sortDirection = 'ASC';         
                
                sortExp = value;    
            }    
    }     
    
    public String getSortDirection(){
        if (sortExpression == null || sortExpression == '')   
            return 'ASC';     
        else     
            return sortDirection;   
    }                  
    
    public void setSortDirection(String value){    
        sortDirection = value;     
    }          
    
    public List<Account> getAccounts(){
        return pageAccounts;     
    }     
    public Integer getPageSize(){    
        return pageSize;     
    }     
    public Boolean getPreviousButtonEnabled(){    
        return !(pageNumber > 1);     
    }     
    public Boolean getNextButtonDisabled(){     
        if (accounts == null)
            return true;     
        else
            return ((pageNumber * pageSize) >= accounts.size());     
    }     
    
    public Integer getTotalPageNumber(){     
        
        if (totalPageNumber == 0 && accounts !=null){   
            totalPageNumber = accounts.size() / pageSize;     
            Integer mod = accounts.size() - (totalPageNumber * pageSize);     
        
            if (mod > 0)     
                totalPageNumber++;     
             
        }     
        return totalPageNumber;     
    }    
    public MyPagingController() {   
        pageNumber = 0;
        totalPageNumber = 0;
        pageSize = 4;
        ViewData();     
    }     
    public PageReference ViewData(){
        accounts = null;
        totalPageNumber = 0;  
        BindData(1);     
        return null;    
    }    
    private void BindData(Integer newPageIndex) {    
        try{    
            string sortFullExp = sortExpression  + ' ' + sortDirection;
            string aName ='AKS foods';
            if (accounts == null)    
                accounts = Database.query('Select id, Name, BillingCity, BillingCountry, Phone from Account order by ' + sortFullExp );
            
            pageAccounts = new List<Account>{};    
            Transient Integer counter = 0;  
            Transient Integer min = 0;    
            Transient Integer max = 0;    
            if (newPageIndex > pageNumber){     
                min = pageNumber * pageSize;
                max = newPageIndex * pageSize;     
            }     
            else{      
                max = newPageIndex * pageSize;     min = max - pageSize;    
            }
            
            for(Account a : accounts){
                counter++;     
                if (counter > min && counter <= max)   
                    pageAccounts.add(a);     
            }     
            
            pageNumber = newPageIndex;
            if (pageAccounts == null || pageAccounts.size() <= 0)
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Data not available for this view.'));
        }     
        catch(Exception ex)   
        {    
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,ex.getMessage()));     
        }     
    }     
    public PageReference nextBtnClick() {   
        BindData(pageNumber + 1);     
        return null;    
    }  
    public PageReference previousBtnClick() {
        BindData(pageNumber - 1);
        return null;    
    }
}


change query and pageSize accordigly.