• D'Mario Lewis
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Im creating map of a map of allocations using a church number as my key. The issue with my code is when I use the map.get(key) function and enter a church number I returns the last element map and I cant understand why. 
private Map<String, Map<String, Decimal>> AboveMinistryShareAllocationMap(List<causeview__Gift_Detail__c> allocationlist){
     
        Map<String, Map<String, Decimal>> Level1Above = new Map<String, Map<String, Decimal>>();
        Map<String, Decimal> Level2Above = new Map<String, Decimal> ();
        
        String churchnumber = allocationlist.get(0).churchnumber;
        Decimal amount = 0;
       
        for(causeview__Gift_Detail__c allocation : allocationlist){
            String allChurch = allocation.churchnumber;
            String fundname  = allocation.fundnote;
            
            if(allChurch.equals(churchnumber)){
                amount += allocation.amount
		Level2Above.put(fundname, amount);
            }
            
            else {
                
                Level1Above.put(churchnumber, Level2Above);
                Level2Above.clear();  
                amount = allocation.causeview__Approved_Amount__c;
                Level2Above.put(fundname, amount); 
                churchnumber = allChurch;
            } 
        }
return Level1Above;
}
public PageReference report(){ 
    	PageReference np = null;
    	
        starts = startDate.format(); //formats date as MM/DD/YYYY 
        ends = endDate.format();
        
        String value = getClassisObject().get(0).getValue();
        
        if(reportObj.equals('church')){
            String[] splitter = churchObj.split(':');
            churchReport(year, splitter[0].trim(), startDate,  endDate);
            
            np = new PageReference('/apex/crcna_MinistryShare_ChurchReport');
        }
        
        if(reportObj.equals('full')){
            List<Account> lstClassis = ClassisList(classisObj, value, reportObj);
            List<Account> lstChurches = ChurchList(lstClassis);
            if(classisObj <> value){  
                lstSubtotals = fullDetail(countryObj, lstChurches, year, startDate, endDate);

            np = new PageReference('/apex/crcna_MinistryShare_ClassisReport');

            }
       }
np.setRedirect(true);
return np;
}
I have this list of lists and when I used this code I only get the last element of the list

//////////////////////////////////////////////////////////// APEX CODE ////////////////////////////////////////////////////////////////////////////////////   
private List<List<MinistrySharesSummary>> ListCollector (List<MinistrySharesSummary> suggestedAmountsList){
        List<List<MinistrySharesSummary>> classisList = new List<List<MinistrySharesSummary>>();
        List<MinistrySharesSummary> churchList = new List<MinistrySharesSummary>();
        
        String tempParent = suggestedAmountsList.get(0).parent;
        for(MinistrySharesSummary ms : suggestedAmountsList){
            
            if(ms.parent == tempParent ){
                churchList.add(ms);     
            }
            else{
                classisList.add(churchList);
                churchList.clear();
                churchList.add(ms);
                tempParent = ms.parent;
            }
        }
        
        return classisList;
    }

 
I borrowed some code from the internet and now I cannot deploy it due to a code coverage error.  Is there any way around this or to fix it?
I have this list of lists and when I used this code I only get the last element of the list

//////////////////////////////////////////////////////////// APEX CODE ////////////////////////////////////////////////////////////////////////////////////   
private List<List<MinistrySharesSummary>> ListCollector (List<MinistrySharesSummary> suggestedAmountsList){
        List<List<MinistrySharesSummary>> classisList = new List<List<MinistrySharesSummary>>();
        List<MinistrySharesSummary> churchList = new List<MinistrySharesSummary>();
        
        String tempParent = suggestedAmountsList.get(0).parent;
        for(MinistrySharesSummary ms : suggestedAmountsList){
            
            if(ms.parent == tempParent ){
                churchList.add(ms);     
            }
            else{
                classisList.add(churchList);
                churchList.clear();
                churchList.add(ms);
                tempParent = ms.parent;
            }
        }
        
        return classisList;
    }