+ Start a Discussion
JosephJJosephJ 

Urgent !!! Pagination functionality not working

Experts please help.

The problem that i'm facing is my my pagination is not working . The QueryLimit does not mark fare ,the table simply searches the word and displays.

Also for "Deleting" records , it is giving me :  List index out of bounds: 4 Error is in expression '{!deleteRow}' in component <apex:commandButton> in page new_test_task_assignment: Class.PagingTasksController1.deleteRow: line 152,.

I'm just messed and struggling.Please help .Thanks in advance .James


public class PagingTasksController1{

    public List<Task> Tasks;
    public Task del;
    public Task taskDel;
    public Integer CountTotalRecords{get;set;}
    public String QueryString {get;set;}
    public Integer OffsetSize = 0;
    private Integer QueryLimit =3 ;
    public List<Task> lstTasks {get;set;}
    public String searchText {get;set;}
    public Integer rowIndex {get;set;}
    public Date mydate;
    public Integer totalCount {get;set;}
    public string sortField = 'Subject';  // default sort column
    private string sApplySOQL = '';
    public List<Task> delattendeeList {get;set;}

    public List<Task> delAttendees {get; set;}
    public PagingTasksController1(ApexPages.StandardController controller) {

     taskDel= (Task)controller.getRecord();
     Tasks = [Select id,Subject,Status,ActivityDate from Task where OwnerId =: taskDel.Id];
    // this.Tasks=Tasks[0];
     totalCount = Tasks.size();

     delattendeeList = new List<Task>();
     delattendees = new List<Task>();
}


// the current sort direction. defaults to ascending
    public String sortDir {
        get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
        set;
    }

    // the current field to sort by. defaults to role name
    public String getsortField() {
        return sortField;
    }

    // the current field to sort by.
    public void setsortField(string value) {
        sortField = value;
    }
            
    // toggles the sorting of query from asc<-->desc
    public void toggleSort() {
        // simply toggle the direction
        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
      
        integer iIndex = sApplySOQL.indexOf('Order By');
        if (iIndex > -1){
          sApplySOQL = sApplySOQL.substringBefore('Order By');
          sApplySOQL = sApplySOQL + ' Order By ' + sortField + ' ' + sortDir +  ' limit ' + QueryLimit + ' offset ' + OffsetSize;
        }
        tasks = Database.query(sApplySOQL );
    }
 
    public PagingTasksController1 (){
        //CountTotalRecords= [select count() from Task];
        //String qStr2= '7/23/2014';
          
    }
   public List<Task> getTasks(){
        if(tasks == null){
            tasks = new List<Task>();
        }
        return tasks;
    }
   public void findTasks(){
        String qStr2 = 'Select count() from Task where Subject like \'%'+searchText+'%\' OR Status like \'%'+searchText+'%\'';
        CountTotalRecords = Database.countQuery(qStr2);
        queryTasks();
    }
   public void  queryTasks(){
        
        String qStr2= searchText;
        String strnormal = '';
        try{
             mydate = date.parse(qStr2);
        }catch(Exception e)
        { }
           
        String strDate = '';
        if(mydate != null) {
         // strnormal = String.valueOf(mydate );
          String[] qstr3 = String.valueOf(mydate).split(' ',2); 
          strDate = ' ActivityDate =  '+ qstr3[0] + ' ';
        }else{
              strDate  =  'Subject like \'%'+searchText +'%\' OR Status like \'%' +searchText+ '%\' Order By '  + sortField;
        }
        String qStr = 'Select OwnerId,Subject,Status,ActivityDate from Task where '  + strDate   ;
        System.debug(qStr );
        sApplySOQL = qStr;
        tasks = Database.query(sApplySOQL );
        //tasks.sort();

    }
  public Boolean getDisablePrevious(){
        if(OffsetSize>0){
            return false;
        }
        else return true;
    }
  public Boolean getDisableNext() {
        if (OffsetSize + QueryLimit < countTotalRecords){
            return false;
        }
        else return true;
    }
  public PageReference Next() {
        OffsetSize += QueryLimit;
        queryTasks();
        return null;
    }
  public PageReference Previous() {
        OffsetSize -= QueryLimit;
        queryTasks();
        return null;
    }
  public PageReference save() {
        update tasks;
        return ApexPages.CurrentPage();
     }
    
  public void deleteRow(){

         rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
         System.debug('row to be deleted ' + rowIndex );
         System.debug('row item to be deleted '+ Tasks[rowIndex]);
         del = Tasks.remove(rowIndex);
         delattendeeList.add(del);
     }
     
  }
Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
It seems like your query limit is 3 , but you are trying to delete 4th records which is generating an exception.

Thanks,
N.J
JosephJJosephJ
Thanks for quick reply. No , even if i'm deleting 1 or  2 or 3 then also the same error.Below is my VF page code.Really stressed.

<apex:page controller="PagingTasksController1" docType="html-5.0">
    <apex:form >
     <apex:variable var="rowNumber" value="{!0}"/>
        <apex:pageBlock title="Tasks" id="pgBlock" >
      
           <apex:pageBlockButtons >
               <apex:commandButton action="{!save}" id="saveButton" value="Save"/>
               <apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
           </apex:pageBlockButtons>
 
        <apex:inlineEditSupport showOnEdit="saveButton, cancelButton"
                    hideOnEdit="editButton" event="ondblclick"
                    changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
 
          <apex:inputText id="searchBox" value="{!searchText}"/>
           <apex:commandButton value="Search" reRender="pgTable,pgBlock" action="{!findTasks}"/>
         
       
       
       
          <apex:pageBlockTable value="{!Tasks}" var="tsk" id="pgTable" >
                 
           <apex:column headerValue="Action" >
            <apex:commandButton value="Delete" action="{!deleteRow}" reRender="pgBlock">
              <apex:param name="rowIndex" value="{!rowNumber}"/>
            </apex:commandButton>
            <apex:variable var="rowNumber" value="{!rowNumber+1}"/>
         </apex:column> 
          
                 
         <!-- <apex:column headerValue="Action" >
            <apex:outputLink value="{!URLFOR($Action.Task.Delete, .id,['retURL'='/apex/New_Test_task_Assignment'])}"> Delete</apex:outputLink>
           </apex:column>  -->
       
       
          <apex:column headerValue="Subject">
              <apex:facet name="header">
                    <apex:commandLink value="Subject" action="{!toggleSort}" rerender="pgTable" >
                    <apex:param name="sortField" value="Subject" assignTo="{!sortField}"/>
                    <apex:outputPanel rendered="{!BEGINS(sortField,'Subject')}">
                        &nbsp;<apex:image value="{!IF(sortDir = 'desc','/img/arrowDown.gif','/img/arrowUp.gif')}"/>
                    </apex:outputPanel>
                    </apex:commandLink>
                </apex:facet>    
              
                  <apex:outputField value="{!tsk.Subject}"/>
           </apex:column>
          
          
           <apex:column headerValue="Status">
               <apex:facet name="header">
                    <apex:commandLink value="Status" action="{!toggleSort}" rerender="pgTable" >
                    <apex:param name="sortField" value="Status" assignTo="{!sortField}"/>
                    <apex:outputPanel rendered="{!BEGINS(sortField,'Status')}">
                        &nbsp;<apex:image value="{!IF(sortDir = 'desc','/img/arrowDown.gif','/img/arrowUp.gif')}"/>
                    </apex:outputPanel>
                    </apex:commandLink>
              </apex:facet>        
 
             <apex:outputField value="{!tsk.Status}"/>
         </apex:column>

          
          
        <!-- <apex:column headerValue="Priority">
            <apex:outputField value="{!tsk.Priority}"/>
        </apex:column> -->
       
        <apex:column headerValue="OwnerId">
            <apex:outputField value="{!tsk.OwnerId}"/>
        </apex:column>
       
        <apex:column headerValue="date">
            <apex:outputField value="{!tsk.ActivityDate}"/>
        </apex:column>  
             
       
     </apex:pageBlockTable>
       <apex:pageBlockButtons >
                <apex:commandButton value="Previous" action="{!Previous}" rerender="pgTable,pgBlock"
                                    status="status" disabled="{!DisablePrevious}" />
                <apex:commandButton value="Next" action="{!Next}" reRender="pgTable,pgBlock"
                                    status="status" disabled="{!DisableNext}" />
                <apex:actionStatus id="status" startText="Please Wait..."/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
  <!--   <apex:enhancedlist type="Activity" height="800" rowsPerPage="50" customizable="False"/> -->
</apex:page>


JosephJJosephJ
Any pomiters N J ??  The code is right , but somewhere there is a silly mistake . Have you checked it in your Org ?