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
Ramesh RageRamesh Rage 

Issue with Pagination for Wrapper Class using StandardSetCOntroller

Hi Friends,

I have a Custom VF page report where i need to display Custom Object Record along with its Attachmnets. So i went for wrapper class to display all the details in single record, As the number of records are more(more than 3000), i went for pagination using Standard Setcontroller. Pagination is not working, not sure what is the issue, can any one tell me what wrong i did in my code or any suggestions to achive pagination for my requiremnet is appeciated.

Below is my code:

public class AgreemnetsAttachmnetsController1 {

  transient public list<Apttus__APTS_Agreement__c> agreementsList {get; set;}
  transient public List<AgreemnetsWrapper> wrapperlist{get;set;}
  transient public list<Attachment> attchmentsList{get; set;}
  transient public map<id,string> agreementMap {get;set;}
  transient public list<user> username{get;set;}


  // Pagination Variables
  //public Integer pageSize {get; set;}
  //public Integer pageNumber {get; set;}
  //public Integer offset {get; set;}
  //public integer noOfRecords {get; set;}
  transient Public Apexpages.StandardSetController con {get; set;}
  transient Public Integer size{get; set;}
  transient Public Integer totalRecords{get; set;}
  transient static final String s = '012a0000000ATI9AAO';
  transient static final String s1= 'Cancelled';

  Public AgreemnetsAttachmnetsController1 (){
    
      pageNumber = 0;
      Size = 1000;
      getAgreemnetswithAttachments();
  }

  Public list<Apttus__APTS_Agreement__c> agreements
     {
       get
        {
          If(con != null){
              agreements = (list<Apttus__APTS_Agreement__c>)con.getRecords();
              return agreements ;
           }Else{
              agreements = null;
              return null;
           }
        }
        set;
     }

  Public Void getAgreemnetswithAttachments(){
      wrapperlist = New List<AgreemnetsWrapper>();

      String baseQuery ='select id,Apttus__FF_Agreement_Number__c,name,Apttus__Status_Category__c,Account_Agreement_Text__c,RecordType.Name,Apttus_Approval__Approval_Status__c,CreatedDate,Owner.FirstName,Owner.LastName,Apttus__Contract_Start_Date__c,Apttus__Contract_End_Date__c,Apttus__Perpetual__c FROM Apttus__APTS_Agreement__c where RecordTypeId=:s and  Apttus__Status_Category__c != :s1';
      con = New Apexpages.StandardSetController(Database.getQueryLocator(baseQuery));
      con.setPageSize(size);
      totalRecords= con.getResultSize();
     
      set<id> myset=new set<id>();
     for(Apttus__APTS_Agreement__c   ap:agreements)
     {
             myset.add(ap.id);
     }
     attchmentsList =new list<Attachment>();
      attchmentsList = [select id,Name,parentid from Attachment where ParentId IN :myset];
      System.debug('----------------'   +attchmentsList);
     
    
      map<id,list<attachment>> groupbyMap = new  map<id,list<attachment>>();
     
      for(Attachment a : attchmentsList)
      {
         List<attachment> groupbyList=new list<attachment>();
        if(groupbymap.containskey(a.parentid))
         {
            groupbyList=groupbyMap.get(a.parentid);
            groupbyList.add(a);
            groupbyMap.put(a.parentid,groupbylist);
         }
        else
        {
           groupbyList.add(a);
           groupbymap.put(a.parentid,groupbyList);
        }
     }
  
     for(Apttus__APTS_Agreement__c a : agreements)
      {
              AgreemnetsWrapper wp = new AgreemnetsWrapper();
              wp.Agrid=a.id;
              wp.AgreementName=a.Name;
              wp.RecordType=a.Recordtype.name;
              wp.AgreementNumber=a.Apttus__FF_Agreement_Number__c;
              wp.Status=a.Apttus__Status_Category__c;
              wp.Approvalstatus =a.Apttus_Approval__Approval_Status__c;
              wp.Createddate=a.CreatedDate;
              wp.Owner=a.owner.FirstName+a.owner.Lastname;
              wp.AGSD=a.Apttus__Contract_Start_Date__c;
              wp.AGED=a.Apttus__Contract_End_Date__c;
              wp.Perpetual= a.Apttus__Perpetual__c;
              wp.AgreementAccount=a.Account_Agreement_Text__c;
              wp.relatedattachmentList=groupbyMap.get(a.id);
              if(groupbyMap.containskey(a.id))
          wrapperlist.add(wp);

      }
}
public Boolean hasNext {
        get {
            return Con.getHasNext();
        }
        set;
    }
    public Boolean hasPrevious {
        get {
            return Con.getHasPrevious();
        }
        set;
    }

    public Integer pageNumber {
        get {
            return Con.getPageNumber();
        }
        set;
    }

    public void first() {
       Con.first();
    }

    public void last() {
       Con.last();
    }

    public void previous() {
        Con.previous();
    }

    public void next() {
       Con.next();
       system.debug('pageNumber :'+pageNumber );
       system.debug('hasNext :'+hasNext );
    }

public pagereference ExportExcel()
                {
                    pagereference p = new pagereference('/apex/ExportExcel');
                    return p;
                   
                 }
  Public Class AgreemnetsWrapper {
    Public id Agrid{get;set;}
    Public String AgreementNumber{get;set;}
    Public String AgreementName{get;set;}
    public String AttachmentName{get;set;}
    public string RecordType{get;set;}
    public string Approvalstatus {get;set;}
    public datetime Createddate{get;set;}
    public date AGSD{get;set;}
    public date AGED{get;set;}
    public boolean Perpetual{get;set;}
    public string Owner{get;set;}
    public string agreementId {get;set;}
    Public string Status{get;set;}
    public string AgreementAccount{get;set;}
    public list<attachment> relatedattachmentList {get;set;}
   
    public attachment attachmnetwrapper {get;set;}
    Public Apttus__APTS_Agreement__c agreemnetwrapper {get; set;}
  }
}


Any help is appreciated..!!!
Thank you verymuch in advance..!!
Ramesh
Ramu_SFDCRamu_SFDC
Hi Follow the guidelines explained in the below article.

http://hisrinu.wordpress.com/2012/01/09/pagination-using-standardsetcontroller/

Hope this helps..!!
Amit Chaudhary 8Amit Chaudhary 8
If you are still looking for solution. Then Please check below blog :-
http://amitsalesforce.blogspot.in/2014/11/pagination-with-wrapper-class-with.html

Thanks,
Amit Chaudhary
Amit Chaudhary 8Amit Chaudhary 8
Pagination with view state :- http://amitsalesforce.blogspot.in/2014/11/pagination-with-wrapper-class-with.html

Pagination using standardsetcontroller in salesforce:-  http://amitsalesforce.blogspot.in/2015/04/pagination-using-standardsetcontroller.html