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
d.tejdeep@nicomatic.ind.tejdeep@nicomatic.in 

Map key not found error

controller:
public class quoteController{
       Public set<Quote_line_item__c> acclist{get ; set;}
       Public string parentname{get ; set;}
       Public string childname{get ; set;}
     Public Map<Quote_line_item__c,list<batch__c>> blist{ get; set;}
     public list<batch__c> ctlist{get; set;}
     integer count;
     Integer bcount;
    
        public quoteController(){
              count=1; 
              bcount=1; 
         acclist=new set<Quote_line_item__c>();      
         blist=new Map<Quote_line_item__c,list<batch__c>>();
         Quote_line_item__c acc= new Quote_line_item__c(Master_Id__c='Qli'+count,Name='teja');
         system.debug(acc.Master_Id__c);
         ctlist=new list<batch__c>();
        // batch__c ct=new batch__c(Dummy_field__c='BTH'+bcount,Quote_line_item__r=new Quote_line_item__c(Master_Id__c='Qli'+count));         
           batch__c ct=new batch__c(Dummy_field__c='BTH'+bcount);     
         system.debug(ct.Dummy_field__c);
         ctlist.add(ct);
         blist.put(acc,ctlist); 
         acclist.add(acc);
         
    }

       Public void addparent(){
         count=count+1;
         bcount=bcount+1;
         Quote_line_item__c acc= new Quote_line_item__c(Master_Id__c='Qli'+count);
         ctlist=new list<batch__c>();
         batch__c ct=new batch__c(Dummy_field__c='BTH'+bcount,Quote_line_item__r=new Quote_line_item__c(Master_Id__c='Qli'+count));
         ctlist.add(ct);
         blist.put(acc,ctlist);
         acclist.add(acc);
       }
       Public Void addchild(){
       count=count+1;
       bcount=bcount+1;
       Quote_line_item__c acc= new Quote_line_item__c(Master_Id__c=parentname);
       list<batch__c> ctlist=blist.get(acc);
       batch__c ct=new batch__c(Dummy_field__c='BTH'+bcount,Quote_line_item__r=new Quote_line_item__c(Master_Id__c=parentname));
       ctlist.add(ct);
       blist.put(acc,ctlist);
       } 
       Public void deletechild(){
       list<batch__c> b=new list<batch__c>();
       batch__c ct=new batch__c(Dummy_field__c=childname,Quote_line_item__r=new Quote_line_item__c(Master_Id__c=parentname));
       b.add(ct);
       b.clear();
      }
      Public Void deleteparent(){
      Quote_line_item__c acc= new Quote_line_item__c(Master_Id__c=parentname);
      blist.remove(acc);
     }
    Public pagereference save(){
Map<Integer,List<batch__c>> mapIndexWithBatch = new Map<Integer,List<Batch__c>>();

// Insert quote line items and prepare map of index and batch
List<Quote_line_item__c> listInsertQuoteLineItem = new List<Quote_line_item__c>();
Integer intCount = 0;
for (Quote_line_item__c objQuoteLineItem:blist.KeySet()) {
    listInsertQuoteLineItem.Add(objQuoteLineItem);
    mapIndexWithBatch.put(intCount,blist.Get(objQuoteLineItem));
    intCount++;
}
Insert listInsertQuoteLineItem;

// Prepare list of batch and assign quote line item id based on index
// and insert list of batch
List<Batch__c> listInsertBatch = new List<Batch__c>();
for (Integer intCurrentIndex:mapIndexWithBatch.KeySet()) {
    for (Batch__c objBatch:mapIndexWithBatch.Get(intCurrentIndex)) {
        objBatch.Quote_line_item__c = listInsertQuoteLineItem[intCurrentIndex].Id;
        listInsertBatch.Add(objBatch);
    }
}
Insert listInsertBatch;
  
      return null;
      }
  }

Visualforce Page:
<apex:page Controller="quoteController" showHeader="false">
<apex:form >
   <apex:pageBlock title="Bulk Quotelineitem Create" id="wtable">
      <apex:pageBlockTable value="{!Blist}" var="a" >
      <apex:column >

         </apex:column>
         <apex:column headerValue="Parent">
            <apex:inputField value="{!a.Name}"/>
         </apex:column>
         <apex:column headerValue="Name">
            <apex:outputField value="{!a.Master_Id__c}"/>
         </apex:column>
         <apex:column >
         <apex:commandButton value="Delete Parent" action="{!deleteparent}" rerender="wtable">
         <apex:param assignTo="{!parentname}" value="{!a.name}" Name="parentname777"/>
         </apex:commandButton>
         </apex:column>
         <apex:column breakBefore="true" colspan="2" >
          <apex:pageblocktable value="{!blist[a]}" var="c" >
        <apex:column headerValue="Contact Name">
           <apex:inputField value="{!c.Name}"/>
         </apex:column>
         <apex:column headerValue="Dummy Field">
          <apex:inputField value="{!c.Dummy_field__c}"/>
         </apex:column>
         <apex:column >
          <apex:commandlink Value="Add child" action="{!addchild}" rerender="wtable">
         <apex:param assignTo="{!parentname}" value="{!a.Master_Id__c}" Name="parentname777"/>
         </apex:commandlink>
         </apex:column>
         <apex:column >
         <apex:commandlink Value="Delete Child" action="{!deletechild}" onclick="remove(this)"  rerender="wtable">
         <apex:param assignTo="{!parentname}" value="{!a.Master_Id__c}" Name="parentname777"/>
         <apex:param assignTo="{!childname}" value="{!c.Dummy_field__c}" Name="parentname777"/>
         </apex:commandlink>
         </apex:column>
         </apex:pageblocktable>
         </apex:column>  
    </apex:pageBlockTable>
   </apex:pageblock>
   <apex:commandButton Value="Add parent"   action="{!addparent}" rerender="wtable"/>
   <apex:commandButton Value="save"   action="{!save}" rerender="wtable"/>
 </apex:form>
</apex:page>

Map key a0LN0000002vFjWMAU not found in map
Error is in expression '{!blist[a]}' in component <apex:pageBlockTable> in page newlineitempage

I am getting like this error .Help me to solve this error 

Thanks in Advance


 
Amit Chaudhary 8Amit Chaudhary 8
Please try below code . I hope that will help you.
<apex:page Controller="quoteController" showHeader="false">
<apex:form >
   <apex:pageBlock title="Bulk Quotelineitem Create" id="wtable">
      <apex:pageBlockTable value="{!Blist}" var="a" >
      <apex:column >

         </apex:column>
         <apex:column headerValue="Parent">
            <apex:inputField value="{!a.Name}"/>
         </apex:column>
         <apex:column headerValue="Name">
            <apex:outputField value="{!a.Master_Id__c}"/>
         </apex:column>
         <apex:column >
         <apex:commandButton value="Delete Parent" action="{!deleteparent}" rerender="wtable">
         <apex:param assignTo="{!parentname}" value="{!a.name}" Name="parentname777"/>
         </apex:commandButton>
         </apex:column>
         <apex:column breakBefore="true" colspan="2" >
			  <apex:pageblocktable value="{!blist[a]}" var="c" rendered="{!if( blist[a].size > 0 , true,false ) }" >
					<apex:column headerValue="Contact Name">
					   <apex:inputField value="{!c.Name}"/>
					 </apex:column>
					 <apex:column headerValue="Dummy Field">
					  <apex:inputField value="{!c.Dummy_field__c}"/>
					 </apex:column>
					 <apex:column >
					  <apex:commandlink Value="Add child" action="{!addchild}" rerender="wtable">
					 <apex:param assignTo="{!parentname}" value="{!a.Master_Id__c}" Name="parentname777"/>
					 </apex:commandlink>
					 </apex:column>
					 <apex:column >
					 <apex:commandlink Value="Delete Child" action="{!deletechild}" onclick="remove(this)"  rerender="wtable">
					 <apex:param assignTo="{!parentname}" value="{!a.Master_Id__c}" Name="parentname777"/>
					 <apex:param assignTo="{!childname}" value="{!c.Dummy_field__c}" Name="parentname777"/>
					 </apex:commandlink>
					 </apex:column>
			 </apex:pageblocktable>
         </apex:column>  
    </apex:pageBlockTable>
   </apex:pageblock>
   <apex:commandButton Value="Add parent"   action="{!addparent}" rerender="wtable"/>
   <apex:commandButton Value="save"   action="{!save}" rerender="wtable"/>
 </apex:form>
</apex:page>

Please let us know if this will help you
Thanks,
Amit Chaudhary
d.tejdeep@nicomatic.ind.tejdeep@nicomatic.in
Hi I am geting this error

Incorrect parameter type for subscript. Expected Number, received Text
Error is in expression '{!if( blist[a].size > 0 , true,false )}' in component <apex:pageBlockTable> in page newlineitempage
Amit Chaudhary 8Amit Chaudhary 8
Issue this that IN Map in VF page blist[a] will return text like {key,key2,key3}. 

Please check below blog. I hope that will help you.
http://ankitgsfdc.blogspot.in/2014/05/we-can-check-map-contains-key-on.html
Please let us know if that will help you.
 
Shrikant BagalShrikant Bagal
Please try following code:
 
<apex:page Controller="quoteController" showHeader="false">
<apex:form >
   <apex:pageBlock title="Bulk Quotelineitem Create" id="wtable">
      <apex:pageBlockTable value="{!Blist}" var="a" >
      <apex:column >

         </apex:column>
         <apex:column headerValue="Parent">
            <apex:inputField value="{!a.Name}"/>
         </apex:column>
         <apex:column headerValue="Name">
            <apex:outputField value="{!a.Master_Id__c}"/>
         </apex:column>
         <apex:column >
         <apex:commandButton value="Delete Parent" action="{!deleteparent}" rerender="wtable">
         <apex:param assignTo="{!parentname}" value="{!a.name}" Name="parentname777"/>
         </apex:commandButton>
         </apex:column>
         <apex:column breakBefore="true" colspan="2" >
			  <apex:pageblocktable value="{!blist[a]}" var="c" rendered="{!NOT(blist[a].empty)}" >
					<apex:column headerValue="Contact Name">
					   <apex:inputField value="{!c.Name}"/>
					 </apex:column>
					 <apex:column headerValue="Dummy Field">
					  <apex:inputField value="{!c.Dummy_field__c}"/>
					 </apex:column>
					 <apex:column >
					  <apex:commandlink Value="Add child" action="{!addchild}" rerender="wtable">
					 <apex:param assignTo="{!parentname}" value="{!a.Master_Id__c}" Name="parentname777"/>
					 </apex:commandlink>
					 </apex:column>
					 <apex:column >
					 <apex:commandlink Value="Delete Child" action="{!deletechild}" onclick="remove(this)"  rerender="wtable">
					 <apex:param assignTo="{!parentname}" value="{!a.Master_Id__c}" Name="parentname777"/>
					 <apex:param assignTo="{!childname}" value="{!c.Dummy_field__c}" Name="parentname777"/>
					 </apex:commandlink>
					 </apex:column>
			 </apex:pageblocktable>
         </apex:column>  
    </apex:pageBlockTable>
   </apex:pageblock>
   <apex:commandButton Value="Add parent"   action="{!addparent}" rerender="wtable"/>
   <apex:commandButton Value="save"   action="{!save}" rerender="wtable"/>
 </apex:form>
</apex:page>

If its helps, please mark as best answer so it will help to other who will serve same problem.
​Thanks! 
Shrikant BagalShrikant Bagal
If its helps, please mark as best answer so it will help to other who will serve same problem.
​Thanks! 
d.tejdeep@nicomatic.ind.tejdeep@nicomatic.in
Still i am facing the same error nothing worked for me.