1

//VF Page

 <apex:page controller="RetrieveClasses">
    <apex:form >
  <apex:pageBlock >

         <apex:pageBlockTable value="{!wrapList}" var="a" style="border-width:thin;border-style:solid;width:100%;border-color:gray;">
         <apex:column >
             <apex:inputCheckbox value="{!a.ischeck}"/>
         </apex:column>
        <apex:column value="{!a.ac.name}" headerValue="Apex Classes"/>
        <apex:column value="{!a.ac.createdby.name}" headerValue="Created By" />
        <apex:column value="{!a.ac.createdDate}" headerValue="Created Date" />

        </apex:pageblockTable>


            <!-- <apex:pageBlockTable value="{!pageList}" var="b" style="border-width:thin;border-style:solid;width:100%;border-color:gray;">
                 <apex:column >
                    <apex:inputCheckbox value="{!isCheck}"/>
                </apex:column>
                <apex:column value="{!b.name}" headerValue="Apex Pages"/>
                 <apex:column value="{!b.createdby.name}" headerValue="Created By" />
                <apex:column value="{!b.createdDate}" headerValue="Created Date" />
            </apex:pageblockTable> -->


  </apex:pageBlock>
</apex:form>        
</apex:page>

//Controller

 public class RetrieveClasses{
    public List <wrapClassPages> wrapList {get;set;}

    public RetrieveClasses()
    { 
        wrapList = new List<wrapClassPages>();
            for(ApexClass a : [SELECT id, name,createdby.name,createdDate from ApexClass])
            {
                wrapList.add(new wrapClassPages(a, false));
            }


        System.debug('>>>>>WrapList>>>>>>>>>>' +wrapList); 

        /*
            for(ApexPage p: [Select id, name, createdby.name, createdDate from ApexPages])
            {
                 wrapList.add(new wrapClassPages(p, false));    
            }
        */

    }

    public class wrapClassPages
    {
        public ApexClass ac{get;set;}
        //public ApexPage ap{get;set;}
        public Boolean ischeck {get;set;}

        public wrapClassPages(ApexClass ac,Boolean v)
        {
            this.ac = ac;
            //this.ap = ap;
            ischeck = v;
        }
    }
}

I'm trying to write a wrapper class to display Apex classes and VF pages from my org.

I'm done with half part, adding apex classes, but I'm unable to add VF pages with same approach.

4 Answers 4

1

You don't have a variable for vf pages in your wrapper. You need to change your wrapper class likes this;

public class wrapClassPages
    {
        public ApexClass ac{get;set;}
        public ApexPage ap{get;set;}
        public Boolean ischeck {get;set;}

        public wrapClassPages(ApexClass ac, ApexPage ap, Boolean v)
        {
            this.ac = ac;
            this.ap = ap;
            ischeck = v;
        }
    }

then change your controller like this;

public List <wrapClassPages> wrapList {get;set;}
    public List <wrapClassPages> pageList {get;set;}
public RetrieveClasses()
    { 
        wrapList = new List<wrapClassPages>();
        pageList = new List<wrapClassPages>();
            for(ApexClass a : [SELECT id, name,createdby.name,createdDate from ApexClass])
            {
                wrapList.add(new wrapClassPages(a,null, false));
            }


        System.debug('>>>>>WrapList>>>>>>>>>>' +wrapList); 


            for(ApexPage p: [Select id, name, createdby.name, createdDate from ApexPage])
            {
                 pageList.add(new wrapClassPages(null, p, false));    
            }


    }

Finally change your page like this;

    </apex:pageblockTable>


         <apex:pageBlockTable value="{!pageList}" var="b" style="border-width:thin;border-style:solid;width:100%;border-color:gray;">
             <apex:column >
                <apex:inputCheckbox value="{!isCheck}"/>
            </apex:column>
            <apex:column value="{!b.ap.name}" headerValue="Apex Pages"/>
             <apex:column value="{!b.ap.createdby.name}" headerValue="Created By" />
            <apex:column value="{!b.ap.createdDate}" headerValue="Created Date" />
        </apex:pageblockTable>
1

Try this.

Controller:-

public class RetrieveClasses {
    public List <wrapClassPages> wrapList {get;set;}
    public List <wrapPages> pageList {get;set;}
    public RetrieveClasses() { 
        wrapList = new List<wrapClassPages>();
        pageList = new List<wrapPages>();
        for(ApexClass a : [SELECT id, name,createdby.name,createdDate from ApexClass]) {
            wrapList.add(new wrapClassPages(a, false));
        }
        System.debug('>>>>>WrapList>>>>>>>>>>' +wrapList); 
        for(ApexPage p: [Select id, name, createdby.name, createdDate from ApexPage]) {
             pageList.add(new wrapPages(p, false));    
        }
    }
    public class wrapClassPages {
        public ApexClass ac{get;set;}
        public Boolean ischeck {get;set;}

        public wrapClassPages(ApexClass ac,Boolean v) {
            this.ac = ac;
            ischeck = v;
        }
    }
    public class wrapPages {
        public ApexPage page{get;set;}
        public Boolean ischeck {get;set;}

        public wrapPages(ApexPage page,Boolean v) {
            this.page = page;
            ischeck = v;
        }
    }
}

Vf page:-

<apex:page controller="RetrieveClasses">
    <apex:form >
  <apex:pageBlock >

        <apex:pageBlockTable value="{!wrapList}" var="a" style="border-width:thin;border-style:solid;width:100%;border-color:gray;">
            <apex:column >
                <apex:inputCheckbox value="{!a.ischeck}"/>
            </apex:column>
            <apex:column value="{!a.ac.name}" headerValue="Apex Classes"/>
            <apex:column value="{!a.ac.createdby.name}" headerValue="Created By" />
            <apex:column value="{!a.ac.createdDate}" headerValue="Created Date" />
        </apex:pageblockTable>

        <apex:pageBlockTable value="{!pageList}" var="b" style="border-width:thin;border-style:solid;width:100%;border-color:gray;">
            <apex:column >
                <apex:inputCheckbox value="{!b.page.isCheck}"/>
            </apex:column>
            <apex:column value="{!b.page.name}" headerValue="Apex Pages"/>
            <apex:column value="{!b.page.createdby.name}" headerValue="Created By" />
            <apex:column value="{!b.page.createdDate}" headerValue="Created Date" />
        </apex:pageblockTable>

  </apex:pageBlock>
</apex:form>        
</apex:page>
1

The query is

select id, name, createdby.name, createdDate from ApexPage

You should query from ApexPage not ApexPages.

Also, you need to add another constructor for the ApexPage in your wrapper class:

public class wrapClassPages
{
        public ApexClass ac{get;set;}
        public ApexPage ap{get;set;}
        public Boolean ischeck {get;set;}

        public wrapClassPages(ApexClass ac,Boolean v)
        {
            this.ac = ac;
            ischeck = v;
        }

        public wrapClassPages(ApexPage ap, Boolean v)
        {
            this.ap = ap;
            ischeck = v;
        }
}

And your page would be like so:

<apex:pageBlockTable value="{!pageList}" var="b" style="border-width:thin;border-style:solid;width:100%;border-color:gray;">
                 <apex:column >
                    <apex:inputCheckbox value="{!isCheck}"/>
                </apex:column>
                <apex:column value="{!b.ap.name}" headerValue="Apex Pages"/>
                 <apex:column value="{!b.ap.createdby.name}" headerValue="Created By" />
                <apex:column value="{!b.ap.createdDate}" headerValue="Created Date" />
</apex:pageblockTable>
1

In your wrapper Class, you have to add another constructor to accept ApexPage so that you can populate Classes and Pages in the same list. You have to update the Query for Pages, change from ApexPages to ApexPage as mentioned by N. B. Also add a type check to differentiate between Classes and Pages.

In VF page to render the classes and pages use rendered="{!IF(a.type=='Class',true,false)}" attribute and check the type and show the different values accordingly.

Controller

public class RetrieveClassesPages {
    public List <wrapClassPages> wrapList {get;set;}
    public RetrieveClassesPages(){
        wrapList = new List<wrapClassPages>();
        for(ApexClass a : [SELECT id, name,createdby.name,createdDate from ApexClass]){
            wrapList.add(new wrapClassPages(a, false));
        }
        for(ApexPage p: [Select id, name, createdby.name, createdDate from ApexPage]){
            wrapList.add(new wrapClassPages(p, false));
        }
    }
    public class wrapClassPages{
        public ApexClass ac{get;set;}
        public ApexPage ap{get;set;}
        public Boolean ischeck {get;set;}
        public String type{get; set;}
        public wrapClassPages(ApexClass ac,Boolean v){
            this.ac = ac;
            this.ischeck = v; 
            this.type='Class';
        }
        public wrapClassPages(ApexPage ap,Boolean v){
            this.ap = ap;
            this.ischeck = v; 
            this.type='Page';
        }        
    }
}

VF Page

<apex:page controller="RetrieveClassesPages">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!wrapList}" var="a" style="border-width:thin;border-style:solid;width:100%;border-color:gray;">
                <apex:column >
                    <apex:inputCheckbox value="{!a.ischeck}"/>
                </apex:column>
                <apex:column value="{!a.type}"/>
                <apex:column headerValue="Apex Class/Pages">
                    <apex:outputText value="{!a.ac.name}" rendered="{!IF(a.type=='Class',true,false)}" />
                    <apex:outputText value="{!a.ap.name}" rendered="{!IF(a.type=='Page',true,false)}" />                    
                </apex:column> 
                <apex:column headerValue="Created By">
                    <apex:outputText value="{!a.ac.createdby.name}" rendered="{!IF(a.type=='Class',true,false)}" />
                    <apex:outputText value="{!a.ap.createdby.name}"  rendered="{!IF(a.type=='Page',true,false)}" />                    
                </apex:column>
                <apex:column headerValue="Created Date">
                    <apex:outputText value="{!a.ac.createdDate}" rendered="{!IF(a.type=='Class',true,false)}" />
                    <apex:outputText value="{!a.ap.createdDate}" rendered="{!IF(a.type=='Page',true,false)}" />                    
                </apex:column>
            </apex:pageblockTable>
        </apex:pageBlock>
    </apex:form>        
</apex:page>

You must log in to answer this question.

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