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
JimmydnetJimmydnet 

Suggestion on what data package to use?

Hi!
I am still quite new to VF/APEX and am looking for some direction with my current problem.

I have apx code that builds that data that I need. The issues are that I am required to build this via subqueries.  I am able to output the correct information in the log file. Basically, it works.

The problem that I am having is understanding how I need to package the data to be used on my VF page? I am trying to get my head around sObjects, lists, and sets but am not sure which way to go. With the basic SoQL and sObject I am able to populate the page but, as I mentioned, I need to add additional elements that are outside of the first query. The logic works I just need an idea of how to package it for the APEX page.

Any guidance would be appreciated.

- Jim
Rajiv Penagonda 12Rajiv Penagonda 12
Dougherty, you will have to use wrapper classes to achieve what you are looking for. Below example code should help:

APEX controller:
public class ComplexPageController {
    public class PageDataWrapper {
        public String mRef {get;set;}
        public List<Opportunity> mOpportunities {get;set;}
        public List<Account> mAccounts {get;set;}
        public List<Lead> mLeads {get;set;}
        
        public PageDataWrapper(String aWrapperID) {
            mRef = aWrapperID;
            mOpportunities = new List<Opportunity>();
            mAccounts = new List<Account>();
            mLeads = new List<Lead>();
        }
    }
    
    public List<PageDataWrapper> mComplexPageData {get;set;}
    
    public ComplexPageController() {
        mComplexPageData = new List<PageDataWrapper>();
    }
}

VisualForce Page:
<apex:page controller="ComplexPageController">
    <apex:repeat value="{!mComplexPageData}" var="wrapperInstance">
        <apex:outputText value="{!wrapperInstance.mRef}" />
        
        <apex:repeat value="{!wrapperInstance.mOpportunities}" var="opportunity">
        </apex:repeat>
        
        <apex:repeat value="{!wrapperInstance.mAccounts}" var="account">
        </apex:repeat>
        
        <apex:repeat value="{!wrapperInstance.mLeads}" var="lead">
        </apex:repeat>
    </apex:repeat>
</apex:page>
Wrapper classes allow you to use not sObject placeholders, like a String or other wrapper classes. The above example, demonstrates using multiple blocks each containing set of Opportunities, Accounts and Leads.

Depending on the complexity you may be dealing with, you could also use a wrapper class inside your wrapper class. Make sure to declare the variables as public and {get;set;} so that they are visible to the VisualForce page.

Hope this helps
-Rajiv