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
Collen Mayer 6Collen Mayer 6 

Problems with Map/List for nested for loop

Hi All,
I'm working on a visualforce controller to produce multiple invoices, for any client case that has billing items.   Each billing item has exactly one client case (each client case may have one or more billing items).  I'm getting stuck on the map line below.  Currently I am getting the error, "Incompatible list type List for putAll on Map>".  I'm assuming I can't use putAll in this case?  Can someone suggest an alternative of how this might be done?  Any help, suggestions, improvements are appreciated.  

Thanks,
Collen
 
public class Invoice {
    public ApexPages.StandardController stdCntrlr {get; set;}
    public List<Client_Billing__c> billingList {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;       
    
    public list <BillingEntry> caseList {get; set;}
    public Invoice(ApexPages.StandardController controller) {
        stdCntrlr = controller;
      	mapCaseToBilling = new map <id, List<Client_Billing__c>>();
        mapCaseToBilling.putAll([Select id, (Select id, Client_Case__c from Billing_Items__r) 
                            from AECaseMgmt__Program_Case__c WHERE Id IN :mapCaseToBilling.keySet()]);
        
   for(AECaseMgmt__Program_Case__c cc : CaseQueryResults)
    {
        BillingEntry be = new BillingEntry (cc);
           
        for (Client_Billing__c cb: mapCaseToBilling.get(cc.Id))    
        {
            be.billingList.add(cb);
        }
    }
   
   }


	Public class BillingEntry
    {
        public List<Client_Billing__c> billingList {get;set;}
        Public AECaseMgmt__Program_Case__c Clientcase {get;set;}
        
        public BillingEntry (AECaseMgmt__Program_Case__c cc)
        {
            Clientcase = cc;
            billingList = new list<Client_Billing__c>();
        }
    }
}

 
AvaneeshAvaneesh
Hi Collen 

You Can put your value in with this way.
map<String,List<id>>  allRealtedid = new map<String,List<id>>();
    List<id> work= new List<id>();
    for(Lead ll:[select id,email from lead where email in:allNewEmail])
    {
        if(ll.Email!=NULL)
        {
            work.add(ll.id);
            allRealtedid.put(String.valueOf(ll.Email),work);
         }
    }
marked best if this was help full else let know .


Thank you 
Avaneesh Singh
Pavit SiddhuPavit Siddhu
Hello, 
mapCaseToBilling.putAll([Select id, (Select id, Client_Case__c from Billing_Items__r) 
                            from AECaseMgmt__Program_Case__c WHERE Id IN :mapCaseToBilling.keySet()]);

change to
mapCaseToBilling.putAll([Select id, (Select Client_Case__c from Billing_Items__r) 
                            from AECaseMgmt__Program_Case__c WHERE Id IN :mapCaseToBilling.keySet()]);

May be it works.​
Collen Mayer 6Collen Mayer 6
Avaneesh, it looks like your suggestion is close to what I need.  Making the changes you suggest I'm left with:
 
--snip--
mapCaseToBilling = new map <id, List<Client_Billing__c>>();
        caseQueryResults = [SElect id from AECaseMgmt__Program_Case__c];
        
   for(AECaseMgmt__Program_Case__c cc : CaseQueryResults)
    {
        BillingEntry be = new BillingEntry (cc);
        for (Client_Billing__c cb: [Select id, Client_Case__c 
                            from  Client_Billing__c WHERE Client_Case__c = :cc.id ])    
        {
        	billinglist.add(cb);
        }
        MapCasetoBilling.put(cc.Id,billinglist);    
    }


But since I"im in a nested for loop, I need to get the SQL statement out of both for loops.  Can you suggest how I might do that?

Thanks,
Collen