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
Bob_zBob_z 

Map key a0Mf4000009Y567y not found in map in visualforce page repeat inside a repeat

I am getting the following error when i try to preview my visualforce page. "Map key a0Mf4000009Yd63 not found in map
Error is in expression '{!bidsMap[sd.Name]}' in component <apex:repeat> in page test_awarded" I not sure where I'm going wrong and help would be greatly appreciated.

visualforce page:
<apex:page standardcontroller="Account"  extensions="AccountExtensionController"  standardstylesheets="false" showheader="false" applyhtmltag="false">
<form >
<html xmlns="http://www.w3.org/1999/xhtml">
    <body>
    </body>
    
 
   
 
    <table align="center" width="85%" style="font-family: Arial, Helvetica, sans-serif; border-collapse: collapse;  text-align:center;"
               cellpadding="2">
             <apex:repeat var="sd" value="{!bidsList}">
                   
<tr>
<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr"> {!sd.Name}</td>

<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr">${!sd.Site__r.Name}</td></tr>

<apex:repeat var="et" value="{!bidsMap[sd.Name]}"  >
<tr>
<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr"> {!et.Scope__c} {!et.Increment__c}</td>

<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr">${!et.Price__c}</td>

<td style="border-bottom:solid;border-bottom-color:#000000;border-bottom-width:1px;" class="ctr">${!et.Bid_Name__r.Name}</td>
</tr>
  </apex:repeat>

</apex:repeat>
            </table></html>

</form>


</apex:page>




Apex Code:
Public Class AccountExtensionController{
   private Account acc;
   public List<Bids_Sent__c> bidsList {get;set;}
   public Map<String,List<Site_Bid_Details__c>>  bidsMap {get;set;}
   public AccountExtensionController(ApexPages.StandardController sc){
       acc = (Account)sc.getRecord();
       bidsList = new List<Bids_Sent__c>();
       bidsList = [SELECT Id,Name,Site__r.Name FROM Bids_Sent__c WHERE Awarded__c =: acc.Id];
    Set<Id> bidId = new  Set<Id>();  
    for(Bids_Sent__c bs : bidsList){
       bidId.add(bs.Id);
    }
     
    bidsMap = new Map<String,List<Site_Bid_Details__c>> ();
    for(Site_Bid_Details__c bd : [SELECT Id, Bid_Name__r.Name,Increment__c,Price__c FROM Site_Bid_Details__c WHERE Bid_Name__c IN : bidId]){
        if(bidsMap.containsKey(bd.Bid_Name__r.Name)){
           bidsMap.get(bd.Bid_Name__r.Name).add(bd);
        }
        else{
            bidsMap.put(bd.Bid_Name__r.Name,new List<Site_Bid_Details__c>{bd});
        }
    } 

}

}

 
MKRMKR
Hi,

Could it be that there is no Site_Bid_Details__c for one of the Bids_Sent__c? If you try initializing the map first with initial lists and then add Site_Bid_Details__c there. So replace lines 14-22 with the following lines.
bidsMap = new Map<String,List<Site_Bid_Details__c>> ();
for(Bids_Sent__c bs : bidsList) {
    bidsMap.put(bs.Name, new List<Site_Bid_Details__c>());
}
for(Site_Bid_Details__c bd : [SELECT Id, Bid_Name__r.Name,Increment__c,Price__c FROM Site_Bid_Details__c WHERE Bid_Name__c IN : bidId]){
    bidsMap.get(bd.Bid_Name__r.Name).add(bd);
}
Regards,
Mkr