1

**** EDITED:

I have a map of lists in my controller:

public Map <id,List<Client_Billing__c>> mapCaseToBilling {get;set;}       

For some reason, my page is never getting inside the inner repeat loop. I've checked the debug log and my map and list is populating. Can someone help me troubleshoot what might be going on?

<apex:page StandardController="AECaseMgmt__Program_Case__c" extensions="Invoice" >
    <apex:repeat value="{!MapCasetoBilling}" var="Key">
        This will print:{!Key}
        <apex:repeat value="{!MapCasetoBilling[Key]}" var="BillingItem">
            This will not print/will never get inside this loop.
            <apex:outputField value="{!BillingItem.Name}" />
        </apex:repeat>
    </apex:repeat>
</apex:page>

Here is my entire extension:

public class Invoice {
    public ApexPages.StandardController stdCntrlr {get; set;}
    public List<Client_Billing__c> billingList {get;set;}
    public List<Client_Billing__c> tempbillingList {get;set;}
    public List<AECaseMgmt__Program_Case__c> CaseQueryResults {get;set;}
    public AECaseMgmt__Program_Case__c Clientcase {get;set;}
    public Map <id,List<Client_Billing__c>> mapCaseToBilling {get;set;}       


    public Invoice(ApexPages.StandardController controller) {
        stdCntrlr = controller;
        mapCaseToBilling = new map <id, List<Client_Billing__c>>();
        tempbillinglist = new List<Client_Billing__c>();
        caseQueryResults = [Select id, CC_Case__c, name from AECaseMgmt__Program_Case__c 
                           Where id IN (SELECT Client_Case__c FROM Client_Billing__c)];
        Billinglist = [Select id, Client_Case__c, name from  Client_Billing__c]; 


     for(AECaseMgmt__Program_Case__c cc : CaseQueryResults)
        {
            System.debug(LoggingLevel.Info, 'Client Case pulled=' + cc.CC_Case__c);
            for (Client_Billing__c cb: BillingList)    
            {
                If(cb.Client_Case__c == cc.id)
                {
                    tempbillinglist.add(cb);

                }
            }
            MapCasetoBilling.put(cc.Id,tempbillinglist);
            If (tempbillinglist != null)
            {   
                tempbillinglist.clear();
            }
        }
    }
}
  • Can you show your entire extension? – Adrian Larson Jun 8 '17 at 18:18
  • 4
    That code isn't quite right: it should be <apex:outputField value="{!BillingItem.Name}" /> – sfdcfox Jun 8 '17 at 18:37
  • Thanks, sfdcfox. I made the change. Still not getting inside the second repeat so any feedback there would be much appreciated! – cmayer10 Jun 8 '17 at 20:25
1

Clearing out your temporary variable every iteration of your loop is why you don't see any data.

I recommend this grouping algorithm. It's more concise and there is no need to store temporary variables:

caseToBilling = new Map<Id, List<Client_Billing__c>>();
for (Client_Billing__c record : [SELECT Client_Case__c, Name FROM  Client_Billing__c])
{
    if (!caseToBilling.containsKey(record.Client_Case__c))
        caseToBilling.put(record.Client_Case__c, new List<Client_Billing__c>()
    caseToBilling.get(record.Client_Case__c).add(record);
}

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.