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
Mak OneMak One 

Want to pass List in constructor without specifying type as it can take list of any type

I am writing a wrapper class to to show atmost 100 elements of list using offset:

class Pg{
    public Integer displayLimit{get;set;}
    public Integer displayOffset{get;set;}
    public Boolean disableNext{get;set;}
    public Boolean disablePrev{get;set;}
    List collection;
   
    public Pg(){}
    public Pg(List collection){
        this.collection=collection;
        this.displayOffset=0;
        this.displayLimit=100;
        this.disablePrev=true;
        if (this.collection.size()>displayLimit) {
            this.disableNext=false;
        } else {
            this.disableNext=true;
        }
    }
   
    public void next(){
        this.displayOffset=this.displayOffset+displayLimit;
        if (this.collection.size()<displayOffset+displayLimit) {
            this.disableNext=true;
        }
        this.disablePrev=false;
    }

    public void prev(){
        this.displayOffset=this.displayOffset-displayLimit;
        if (this.displayOffset==0) {
            this.disablePrev=true;
        }
        this.disableNext=false;
    }
   
}

But here it is not allowing me to give List collection;
It needs something like List<Object> collection. Expecting Angle bracket after List.

But I want that I should able to pass List of any collection in constructor.

How to achieve this?
Vi$hVi$h
You can try with List<Sobject> in this case.
Mak OneMak One
There is list of String and list of some other Wrapper classes which I need to pass in it.
Mak OneMak One
Wow! List<Object> worked. I tried this after trying List<sObject>.

But now I am unable to referer to variables in that list inside Visualforce Page. :(
Vi$hVi$h
From what I understand , I guess you will have to pass List of a wrapper class(wrapper class will consist of all data types and all wrapper classes you want).
get set this on VF and then reference it ..
Jim JamJim Jam
Why are you not able to access them?

say, for example, list is populated as follows ..

public list<Object> getobjList(){
        list<Object> objList = new list<Object>();
       
        objList.add('item 1');
        objList.add('item 2');
        objList.add(3);
        objList.add([select id from Account limit 2]);  
       
        return objList;
    }

then VF page can display like this ..

         <apex:pageBlockTable value="{!objList}" var="item">
              <apex:column headerValue="Item" value="{!item}" />
             
          </apex:pageBlockTable>

or ..

<apex:outputText value="{!objList[3][0]}" />

will display the first item in the list (the Account query) which is the last element of the objList.
Mak OneMak One
I wanted to display it like objList[3][0].some_Field_Of_Standard_Object when it is sObject.
When it is wrapper then objList[3][0].some_Wrapper_Class_Field.

And what Visualforce page knows if it is List of Object so it does NOT contain any of fields like some_Field_Of_Standard_Object, some_Wrapper_Class_Field.