1

I have a Custom VF page report where i need to display Custom Object Record along with its Attachments. 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 StandardSetcontroller. 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 achieve pagination for my requirement is appreciated.

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;}
  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

1 Answer 1

1

You cannot keep the setController variable as transient.. because set controller should keep its state even across the page <->control interactions. Since you defined it as Transient, it doesn't retain its state and its data got evaporated after a first traversal from controller to page.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .