I have a list of strings.

I am using these strings to populate three other object lists by querying for this string.

For every iteration I am adding the lists populated to a List of lists. Ex: First populate a case list where field__c = string[i], once populated add this list to a List<List<Case>>.

How should I relate these lists to each other so that I can display the information in datatable with columns that have datatables?

For example:

 - Column 1: String[i] 
 - Column 2: DATATABLE [ listOfList1[i].list1 ]
 - Column 3: DATATABLE [ listOfList2[i].list2 ]

I understand how to use to display list of list information in a datatable, but apex:repeat iterates through all of the lists in the listOfList.

I believe the solution lies in relating or mapping these lists, but I am unable conceptualize how that would work.


I'm still stuck, but created a generic container object that I can store all of these lists/variables in and created a list for the generic object, but still unsure of how to output the variables within that object onto the VFP, particularly the lists.


Since Visualforce can only display your data in a row-by-row process (kind of like a dot matrix printer), you have to build the rows yourself using a wrapper object and extracting the values from your separate lists.

It sounds like you have lists of objects to display, so that wrapper would be like this:

public class RowData {
    public Case theCase { get; set; }
    public MyObj1__c obj1 { get; set; }
    public MyObj2__c obj2 { get; set; }

    public RowData() {}

For each category, you do an integer loop based on the largest list size, and build each wrapper row. Say you are building the Level 1 category:

List<RowData> rowsLevel1 = new List<RowData>();
Integer max; // set to the size of largest list for the category;
for (Integer i = 0; i < max; i++) {
    RowData theRow = new RowData();
    theRow.theCase = (caseList.size() > i ? caseList[i] : new Case());
    theRow.obj1 = (obj1List.size() > i ? obj1List[i] : new MyObj1__c());
    theRow.obj2 = (obj2List.size() > i ? obj2List[i] : new MyObj2__c());

If one list is longer than the others, then the column fields of the other lists must be blank.

To organize all these rows, you use a map of wrapper lists keyed on your category values:

Map<String, List<RowData>> allRows = new Map<String, List<RowData>>();
allRows.add('Level 1', rowsLevel1);

Then you can use nested repeats in your Visualforce page to display all rows grouped by category:

<apex:repeat value="{!allRows}" var="category">
    <apex:repeat value="{!allRows[category]}" var="theRow">
  • Awesome answer and very well explained. Thank you! – S.B. Jul 30 '18 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.