Well, I couldn't find a way to explain in a simple way my issue (thus the poor title).

I am trying to build a page in which I have to separate some records using two fields on it. One of them is a date, an the other is a relationship. First, I would like to build different tables for each date, and then, on those, I would like to list them by result.

This object, however, can have multiple records for the same line in the table, so I would like to create more columns using apex:repeat.

The logic would be to create a map:

Map<Date, Map<Id, List<CustomObject__c>>>

and then iterate over the date using apex:repeat, then over the Id.

<apex:repeat value="{!myMap}" var="data">
    <apex:pageBlockTable value="{!myMap[data]}" var="emp" id="tableProgramacoes">
        <apex:repeat value="{!myMap[data][emp]}" var="prog">
            <apex:outputText value="{!prog.Field__c}"/>

For what I understand, this would be similar to iterating 3 collections, like:

for (Date data : map.keySet())
    for (Id emp : map.get(data).keySet())
        for (CustomObject__c co : map.get(data).get(emp))

Or this is what I think would work, because even if this compiles, when accessing the page, Salesforce raises an error in the expression of the inner repeater. Is there a way to make this iteration work?


Changed code. Still getting errors. Also thanks Adrian for the nice title!

  • you have really asked two separate questions here, the way I see it. I answered your OP, which opened up a separate question. You should roll back your OP and ask a separate question, really.
    – Adrian Larson
    Mar 8, 2016 at 2:46

2 Answers 2


I had trouble making this work with pageBlockTable (or dataTable) but I could with apex:repeat

Using this controller property with unimaginative accountNames:

public map<Date,List<Account>> dateToAccountsMap {
  get {return new map<Date,List<Account>> {   
    Date.newInstance(2020,1,1) => new List<Account> {new Account(name = 'Account2020-00'),
                                                     new Account(name = 'Account2020-01')},
    Date.newInstance(2021,1,1) => new List<Account> {new Account(name = 'Account2021-00'),
                                                     new Account(name = 'Account2021-01')}

  private set;

and this VF:

<apex:page controller="FooController" >

     <apex:repeat  value="{!dateToAccountsMap}" var="dateKey"> <!-- outer -->            
         <apex:outputText value="{!dateKey}"/>
         <apex:repeat value="{!dateToAccountsMap[dateKey]}" var="a"> <!-- inner -->
             <tr><td><apex:outputText value="{!a.name}"/></td></tr>

I rendered (add your own css styling for the HTML table):

Wed Jan 01 00:00:00 GMT 2020
Fri Jan 01 00:00:00 GMT 2021
  • Sounds like my hunch about pageBlockTable may have been correct after all.
    – Adrian Larson
    Mar 8, 2016 at 2:36
  • 1
    @AdrianLarson. Yeah, I couldn't get pageBlocktable to iterate over a map 'get' that returned a list. No doubt sfdcfox or Keith C knows how to do this :-)
    – cropredy
    Mar 8, 2016 at 2:41
  • It seems that Salesforce might have some limitations with pageBlockTable or dataTable. I redid my code to use only repeats, and it worked. Mar 8, 2016 at 11:13

Your prog variable is actually a record, not an index. It represents co in your Apex parallel.

<apex:repeat value="{!myMap[data][emp]}" var="co">
    <apex:outputText value="{!co.Field__c}" />
  • I bet you are right, but after changing things in my code, I get a new error: "Map key null not found in map". I already checked my code for null values, even throwing an exception for this case. Any ideas? Mar 7, 2016 at 17:25
  • @RenatoOliveira Do you still get the error if you comment out the innermost repeat?
    – Adrian Larson
    Mar 7, 2016 at 17:29
  • No. The issue is with the inner repeat, I believe. If I comment it, then the page loads successfully. Mar 7, 2016 at 17:31
  • @RenatoOliveira And if you run that Apex, none of the emp values are null?
    – Adrian Larson
    Mar 7, 2016 at 17:33
  • Precisely. There are no null values. I even ran a query in the db just to make sure of that. Mar 7, 2016 at 17:44

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.