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
Krrish GopalKrrish Gopal 

I'm trying to use pagination at my visualforce page but it shown Authorization Required error, pl help

My Visualforce Page is CaseListView

<apex:page controller="displaycase" title="Exicom Engineer Portal">
 <apex:form id="frm">
 <apex:pageBlock title="Search for cases based on criteria">
 <table width="100%">
  <tr>
     <td width="25%"><strong>Status  </strong>
        <apex:selectList size="1" value="{!getcasestatus}">
        <apex:selectOptions value="{!cstatus}"> </apex:selectOptions>
        </apex:selectList>
     </td>
     <td width="25%"><strong>Type  </strong>
        <apex:selectList size="1" value="{!getcasetype}">
        <apex:selectOptions value="{!ctype}"> </apex:selectOptions>
        </apex:selectList>
     </td>
     <td width="25%"><strong>Reason  </strong>
        <apex:selectList size="1" value="{!getcasereason}">
        <apex:selectOptions value="{!creason}"> </apex:selectOptions>
        </apex:selectList>       
     </td>
     <td width="15%"><strong>Priority  </strong>
        <apex:selectList size="1" value="{!getcasepriority}">
        <apex:selectOptions value="{!cpriority}"> </apex:selectOptions>
        </apex:selectList>      
     </td>
     <td width="10%">
        <apex:commandButton value="Search" action="{!displaycaselist}"/>       
     </td>
  </tr>
 </table>
 </apex:pageBlock>
 <apex:pageBlock title="Search a particular case">
 <apex:pageBlockSection columns="2">
 <apex:inputText value="{!getcasenumber}" label="Case Number"/>
 <apex:commandButton value="Search" action="{!searchcaselist}"/>
 </apex:pageBlockSection>
 </apex:pageBlock>
 </apex:form>
 <c:GenericPaginationComponent Records="{!caselst}" Fields="{!cseFieldLst}" Title="Search Result"/>
</apex:page>
My Apex Class is displaycase

public class displaycase {

public string getcasestatus{get;set;}
public string getcasenumber{get;set;}
public string getcasetype{get;set;}
public string getcasereason{get;set;}
public string getcasepriority{get;set;}

public  void displaycase ()
{
    getcasestatus='';
    getcasetype= '';
    getcasereason= '';
    getcasepriority= '';
    
}
public List<Case> caselst{get;set;}
public List<String> cseFieldLst {get;set;}


public list<selectoption>getcstatus()
{
    list<selectoption>selectopts=new list<selectoption>();
    selectopts.add(new selectoption('',''));
    selectopts.add(new selectoption('Open','Open'));
    selectopts.add(new selectoption('Closed','Closed'));
    selectopts.add(new selectoption('Rejected','Rejected'));
    return selectopts;
}

public list<selectoption>getctype()
{
    list<selectoption>selectoptt=new list<selectoption>();
    selectoptt.add(new selectoption('',''));    
    selectoptt.add(new selectoption('Out of Warranty','Out of Warranty'));
    selectoptt.add(new selectoption('Under AMC','Under AMC'));
    selectoptt.add(new selectoption('Under Warranty','Under Warranty'));
    return selectoptt;
}

public list<selectoption>getcreason()
{
    list<selectoption>selectoptr=new list<selectoption>();
    selectoptr.add(new selectoption('',''));    
    selectoptr.add(new selectoption('Acceptance Testing','Acceptance Testing'));
    selectoptr.add(new selectoption('Breakdown','Breakdown'));
    selectoptr.add(new selectoption('Equipment Complexity','Equipment Complexity'));
    selectoptr.add(new selectoption('Equipment Design','Equipment Design'));
    selectoptr.add(new selectoption('Exceptional','Exceptional'));
    selectoptr.add(new selectoption('Feedback','Feedback'));
    selectoptr.add(new selectoption('Installation','Installation'));
    selectoptr.add(new selectoption('Job Warranty','Job Warranty'));
    selectoptr.add(new selectoption('Other','Other'));
    selectoptr.add(new selectoption('Paid Repair','Paid Repair'));
    selectoptr.add(new selectoption('Performance','Performance'));
    selectoptr.add(new selectoption('Preventive Maintenance','Preventive Maintenance'));    
    return selectoptr;
}

public list<selectoption>getcpriority()
{
    list<selectoption>selectoptp=new list<selectoption>();
    selectoptp.add(new selectoption('',''));
    selectoptp.add(new selectoption('Major','Major'));
    selectoptp.add(new selectoption('Minor','Minor'));
    selectoptp.add(new selectoption('Critical','Critical'));
    return selectoptp;
}

public void displaycaselist()
{
    caselst=new list<case>();
    cseFieldLst=new list<string>();

    String query = 'select CaseNumber,CreatedDate,ClosedDate,IsClosed,IsEscalated,Priority,Reason,Status,Type FROM Case where id !=NULL ';

    if(getcasestatus!=null){
       query+=' and Status=\''+getcasestatus+'\'';
    }
    if(getcasetype!=null){
       query+=' and Type=\''+getcasetype+'\'';
    }
    if(getcasereason!=null){
       query+=' and Reason=\''+getcasereason+'\'';
    }
    if(getcasepriority!=null){
       query+=' and priority=\''+getcasepriority+'\'';
    }

    caselst=Database.query(query+=' ORDER BY CreatedDate DESC');
    cseFieldLst = new List<String>{'CaseNumber','CreatedDate','ClosedDate','IsClosed','IsEscalated','Priority','Reason','Status','Type'};
    
}

public void searchcaselist()
{   
    caselst=new list<case>();
    cseFieldLst=new list<string>();
    if(getcasenumber!=null){
       caselst=Database.query('select CaseNumber,CreatedDate,ClosedDate,IsClosed,IsEscalated,Priority,Reason,Status,Type FROM Case where CaseNumber like \'%'+getcasenumber+'%\' ORDER BY CreatedDate DESC');
       cseFieldLst = new List<String>{'CaseNumber','CreatedDate','ClosedDate','IsClosed','IsEscalated','Priority','Reason','Status','Type'};
    }    
}
}
 
My Visualforce component is  GenericPaginationComponent
<apex:component controller="GenericPaginationComponentContrl">
  
  <!-- Attributes to accept the parameters -->
  <apex:attribute name="Records" Type="Sobject[]" assignTo="{!sObjLst}" required="true" description="Accepts list of records of any object and assign to a variable in controller class"/>
  <apex:attribute name="Fields" Type="String[]" required="true" description="Accepts list of field API names of a sobject in string format"/>
  <apex:attribute name="Title" Type="String" required="true" description="Accepts the title of the section"/>
  
  <!-- Table which displays records along with pagination -->
  <apex:form >
      <apex:pageBlock >
          <apex:pageBlockSection columns="1" title="{!Title}" id="pbSec">
              <apex:pageBlockTable value="{!SobjRecords}" var="sObj">
                  <!-- Dispalys the multiple columns based on the user input -->
                  <apex:repeat value="{!Fields}" var="fld">
                      <apex:column value="{!sObj[fld]}"/>
                  </apex:repeat>
              </apex:pageBlockTable>
              <!-- Dispalys pagination buttons -->
              <apex:panelGrid columns="5">
                  <apex:commandButton value="|<" action="{!con.first}" disabled="{!!con.hasPrevious}" status="pagStatus" reRender="pbSec" title="First"/>
                  <apex:commandButton value="<" action="{!con.previous}" disabled="{!!con.hasPrevious}" status="pagStatus" reRender="pbSec" title="Previouse"/>
                  <apex:commandButton value=">" action="{!con.next}" disabled="{!!con.hasNext}" status="pagStatus" reRender="pbSec" title="Next"/>
                  <apex:commandButton value=">|" action="{!con.last}" disabled="{!!con.hasNext}" status="pagStatus" reRender="pbSec" title="Last"/>
                  <apex:actionStatus startText="Fetching..." id="pagStatus"/>
              </apex:panelGrid>
          </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>
</apex:component>
 
My visualforce component class is GenericPaginationComponentContrl
public class GenericPaginationComponentContrl {
  //Stores the records which are supplied to the 'Records' attribute.
  public Sobject[] sObjLst {get;set;}
  /*
   1. Implementing the pagination with ApexPages.StandardSetController.
   2. We can utilize the built in methods available for the ApexPages.StandardSetController to build the pagination.
   3. Following are the built in mehods we can utilize -
    a. first()
    b. previous()
    c. next()
    d. last()
    e. getHasPrevious() - returns boolean value.
    f. getHasNext() - returns boolean value.
    g. setPageSize(IntegerValue)
  */
  public ApexPages.StandardSetController con {
   get {
    //initializing con with the records.
    if(con == null)
     con = new ApexPages.StandardSetController(sObjLst);
    //Setting the pagination size
    con.setPageSize(5);
    return con;
   }
   set;
  }
  //Method which returns subset of records from the sObjLst.
  public List<sobject> getSobjRecords() {        
   //Type Casing the records and returning to display on the page.
   return (List<sobject>)con.getRecords();
  }
 }

 
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi Krrish4184,

Please look into below link,looks like same issue.
https://developer.salesforce.com/forums/ForumsMain?id=906F00000009A8sIAE


Let us know if it helps.
Krrish GopalKrrish Gopal
I got below error msg when I'm trying to preview CaseListView visualforce page

Apex script unhandled exception by user/organization: 005900000010Iip/00D90000000gy69

Visualforce Page: /apex/CaseListView

caused by: System.NullPointerException: Argument 1 cannot be null

Class.GenericPaginationComponentContrl.__sfdc_con: line 20, column 1
Class.GenericPaginationComponentContrl.getSobjRecords: line 30, column 1