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
AnnaTAnnaT 

Compile Error: Constructor not defined: [ApexPages.StandardSetController].<Constructor>...

Please refer to the following code.

I'd like to use "objList" in Visualforce Page with some paging function

( for example, setCon.getHasPrevious(), setCon.getHasNext(), and so on...).

But I don't know how to set "objLIst" into ApexPages.StandardSetController.

I know I can set "rftList". but I need to use "objList".

 

A part of my code is this.

public with sharing class BulkAccept {

    // Inner Class Definition
    public Class RFT_Category_for_Select {        
        public Boolean checkAccept {get;set;}
        public Boolean checkNa {get;set;}
        public RFT_Category__c obj {get;set;}        
    }    

    // Property 
    public List<RFT_Category_for_Select> objList{get;set;}

    // Constructor
    public BulkAccept() {
        this.objList = new List<RFT_Category_for_Select>();  
        List<RFT_Category__c> rftList = [
            SELECT Id, Name 
              FROM RFT_Category__c 
             WHERE Reject__c = false
             ORDER BY Name
        ];
        for (RFT_Category__c rft : rftList) {
            RFT_Category_for_Select objItem = new RFT_Category_for_Select();
            objItem.checkAccept = false;
            objItem.checkNa     = false;
            objItem.obj         = rft;
            this.objList.add(objItem);
        }
        this.setCon = new ApexPages.StandardSetController(objList);
        this.setCon.setPageSize(50);     
    }

 Thanks in advance for your help.

 

Anna 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Avidev9Avidev9

Well you are facing problem because you are not passing sObjectList to the ApexPages.StandardSetController.  ApexPages.StandardSetController expects sObject.

 

 

Well to overcome this you have to pass list of RFT_Category__c to ApexPages.StandardSetController

 

this.setCon = new ApexPages.StandardSetController(rftList);
//NOW while doing the getrecords you have to convert the list into a wrapper class

 

 

public List < RFT_Category_for_Select > getRecords() {

    List < RFT_Category_for_Select > objList = new List < RFT_Category_for_Select > ();

    for (RFT_Category__c rft: (List < RFT_Category__c > ) setCon.getRecords()) {
        RFT_Category_for_Select objItem = new RFT_Category_for_Select();
        objItem.checkAccept = false;
        objItem.checkNa = false;
        objItem.obj = rft;
        objList.add();
    }
    return objList;
}

 

 

All Answers

Avidev9Avidev9

Well you are facing problem because you are not passing sObjectList to the ApexPages.StandardSetController.  ApexPages.StandardSetController expects sObject.

 

 

Well to overcome this you have to pass list of RFT_Category__c to ApexPages.StandardSetController

 

this.setCon = new ApexPages.StandardSetController(rftList);
//NOW while doing the getrecords you have to convert the list into a wrapper class

 

 

public List < RFT_Category_for_Select > getRecords() {

    List < RFT_Category_for_Select > objList = new List < RFT_Category_for_Select > ();

    for (RFT_Category__c rft: (List < RFT_Category__c > ) setCon.getRecords()) {
        RFT_Category_for_Select objItem = new RFT_Category_for_Select();
        objItem.checkAccept = false;
        objItem.checkNa = false;
        objItem.obj = rft;
        objList.add();
    }
    return objList;
}

 

 

This was selected as the best answer
AnnaTAnnaT

Thank you very much, Avidev9!

It works perfect !!!!