+ Start a Discussion
Anjali Sharma 87Anjali Sharma 87 

One Account with multiple contact on vf page

we have one add account button and del button at time for page load 
When the user click on the add new account then few fields ex: Account name ,Industry and Rating are show with inputFields so the user can
enter the user value and then two more button are display on page to add the contact for that account and delete the contact for that account.
For example one account with multiple contact on row.I have try but actully i have used the two pageblocktable with the Map in which i receive the value in one pageblocktable but when i am using the contact value in pageblocktable it is given the error i.e Map key null not found in map.
I am sharing the code ...

Visualforce page*************

<apex:page controller="Addcontactwrappernewcontroller">
 <apex:form >
   <apex:commandButton value="Add Account" action="{!addaccount}" rerender="panel"/>
    <apex:pageBlock >
    <apex:pageBlockSection columns="2">
     <apex:pageBlockTable var="key" value="{!mywrapperobj}">
      <apex:column headerValue="Account Name">
       <apex:inputField value="{!mywrapperobj[key].accobj.Name}"/>
      <apex:column headerValue="Rating">
       <apex:inputField value="{!mywrapperobj[key].accobj.Rating}"/>
      <apex:column headerValue="Type">
       <apex:inputField value="{!mywrapperobj[key].accobj.Type}"/>
     <apex:pageBlockTable var="innerListVar" value="{!mywrapperobj[key].conlist}">
      <apex:column headerValue="Last Name">
       <apex:inputField value="{!innerListVar.LastName}"/>


public with sharing class Addcontactwrappernewcontroller {

    public String getKey() {
        return null;

    public Integer counter {get;set;}
    public Integer row {get;set;}
    public Map<Integer,wrapperclass> mywrapperobj {get;set;}

    public class wrapperclass{
    public List<Contact> conlist{get;set;}
    public Account accobj{get;set;}
    public wrapperclass(){
    this.conlist = new List<Contact>();
    this.accobj = new Account();

    public Addcontactwrappernewcontroller(){
    counter = 0;
    mywrapperobj = new Map<Integer,wrapperclass>();

   public void addaccount(){
   counter ++;
   mywrapperobj.put(counter,new wrapperclass());

   public void addcontactRow(){
   mywrapperobj.get(row).conlist.add(new Contact());

Thanks in advance