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
SFDC DummySFDC Dummy 

System.DmlException: Insert failed.

Error
-----------

Visualforce Error
Help for this Page

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Related Bank Acc]: [Related Bank Acc]
Error is in expression '{!save}' in component <apex:commandButton> in page add: Class.ManageListController1.save: line 60, column 1

Class.ManageListController1.save: line 60, column 1


 
<apex:page tabstyle="Account" showHeader="false" sidebar="false" Controller="ManageListController1">

<apex:define name="body">
            
            <div style="width:900px;margin: 10px auto 10px auto;background-color:Gray;">
             <apex:image id="theImage" value="{!$Resource.Emami}" width="100" height="100"/>
             <apex:outputLink style="font-weight: bold;float:right;" value="{!URLFOR($Page.LoginPage)}"><b>Back To Home</b></apex:outputLink> 
 <apex:form >
 <style> .headerRow .headerStyle{background-color:#638658;color:#FFFFFF} </style>

   <apex:pageBlock title="Bank Book Entry:">
      
       <div style="width:200px;align=Right;">
      <apex:pageBlockTable value="{!wrappers1}" var="wrapper1" id="wtable1">
      <apex:column headerValue="Date" style="background:gray;" headerClass="headerStyle" >
    <apex:inputField value="{!wrapper1.acc.Txn_Date__c}"/>
</apex:column>
 <apex:column headerValue="Payment Type" style="background:gray;">
    <apex:inputField value="{!wrapper1.acc.Credit_Debit__c}"/>
</apex:column>

<apex:column headerValue="Company Account" style="background:gray;">
    <apex:inputField value="{!wrapper1.acc.Related_Bank_Acc__c}"/>
</apex:column>
         
      </apex:pageBlockTable>
      
          </div>
   <div style="width:500px;margin: 10px auto 10px auto;">
   
      <apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">
      
         
       
         <apex:column headerValue="Ident" style="background:gray;">
            <apex:outputText value="{!wrapper.ident}"/>
         </apex:column>
         <apex:column headerValue="Master Code" style="background:gray;">
            <apex:inputField value="{!wrapper.acc.Entries_Code__c}"/>
         </apex:column>
         <apex:column headerValue="Amount" style="background:gray;">
            <apex:inputField value="{!wrapper.acc.Amount__c}"/>
         </apex:column>
         <apex:column headerValue="Narration" style="background:gray;">
            <apex:inputField value="{!wrapper.acc.Narration__c}"/>
         </apex:column>
          
       <apex:column headerValue="">
            <apex:commandButton value="Enter" action="{!addRows}" rerender="wtable" style="background:pink" >
         <apex:param name="addCount" value="1" assignTo="{!addCount}"/> 
      </apex:commandButton>
         </apex:column>
       
         <apex:column headerValue="Action">
            <apex:commandButton value="Delete" action="{!delWrapper}" rerender="wtable" style="background:Red">
               <apex:param name="toDelIdent" value="{!wrapper.ident}" assignTo="{!toDelIdent}"/> 
            </apex:commandButton>
         </apex:column>
         
      </apex:pageBlockTable>
     </div>
        
        
      <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable" style="width:100px;margin: 10px auto 10px auto;">
         <apex:param name="addCount" value="5" assignTo="{!addCount}"/> 
      </apex:commandButton>
      
      <apex:commandButton value="Save" action="{!save}" style="width:100px;margin: 10px auto 10px auto;"/>
   
    
     </apex:pageBlock>
 </apex:form>
  </div>
        </apex:define>
</apex:page>
public class ManageListController1 
{

    
    public ManageListController1(ApexPages.StandardController controller) {

    }

 public List<AccountWrapper> wrappers {get; set;}
  public List<AccountWrapper> wrappers1 {get; set;}
 public static Integer toDelIdent {get; set;}
 public static Integer addCount {get; set;}
 private Integer nextIdent=0;
  
 public ManageListController1()
 {
  wrappers=new List<AccountWrapper>();
  Wrappers1=new List<AccountWrapper>();
  for (Integer idx=0; idx<1; idx++)
  {
   wrappers.add(new AccountWrapper(nextIdent++));
    wrappers1.add(new AccountWrapper(nextIdent++));
   
  }
 }
  
 public void delWrapper()
 {
  Integer toDelPos=-1;
  for (Integer idx=0; idx<wrappers.size(); idx++)
  {
   if (wrappers[idx].ident==toDelIdent)
   {
    toDelPos=idx;
   }
  }
   
  if (-1!=toDelPos)
  {
   wrappers.remove(toDelPos);
  }
 }
  
 public void addRows()
 {
  for (Integer idx=0; idx<addCount; idx++)
  {
   wrappers.add(new AccountWrapper(nextIdent++));
  }
 }
  
 public PageReference save()
 {
  List<BankBook__c> accs=new List<BankBook__c>();
 
  for (AccountWrapper wrap : wrappers)
  {
   accs.add(wrap.acc);
  }
 insert accs;
  
   
  return new PageReference('/' + Schema.getGlobalDescribe().get('BankBook__c').getDescribe().getKeyPrefix() + '/o');
 }
 
 public pageReference parentPage () {

          return new pageReference('/apex/Receivables');
} 
  
  
  
 public class AccountWrapper
 {
  public BankBook__c acc {get; private set;}
  public Integer ident {get; private set;}
   
  public AccountWrapper(Integer inIdent)
  {
   ident=inIdent;
   acc=new BankBook__c();
  }
 }
}


 
Shrikant BagalShrikant Bagal
Hello Project Dummy,

As per you code you try to insert the "BankBook__c" Object which is wrappered in "AccountWrapper" class.

In Save method we are using "wrappers" Prooperty of class which is used in VF but in VF you are not get input for "Related_Bank_Acc__c" field from User as it might be required for "BankBook__c" object.


Hope its help!! 
SFDC DummySFDC Dummy
Then How it will solved ....
Shrikant BagalShrikant Bagal
Try following VF Code
:
 
<apex:page tabstyle="Account" showHeader="false" sidebar="false" Controller="ManageListController1">

<apex:define name="body">
            
            <div style="width:900px;margin: 10px auto 10px auto;background-color:Gray;">
             <apex:image id="theImage" value="{!$Resource.Emami}" width="100" height="100"/>
             <apex:outputLink style="font-weight: bold;float:right;" value="{!URLFOR($Page.LoginPage)}"><b>Back To Home</b></apex:outputLink> 
 <apex:form >
 <style> .headerRow .headerStyle{background-color:#638658;color:#FFFFFF} </style>

   <apex:pageBlock title="Bank Book Entry:">
      
       <div style="width:200px;align=Right;">
      <apex:pageBlockTable value="{!wrappers1}" var="wrapper1" id="wtable1">
      <apex:column headerValue="Date" style="background:gray;" headerClass="headerStyle" >
    <apex:inputField value="{!wrapper1.acc.Txn_Date__c}"/>
</apex:column>
 <apex:column headerValue="Payment Type" style="background:gray;">
    <apex:inputField value="{!wrapper1.acc.Credit_Debit__c}"/>
</apex:column>

<apex:column headerValue="Company Account" style="background:gray;">
    <apex:inputField value="{!wrapper1.acc.Related_Bank_Acc__c}"/>
</apex:column>
         
      </apex:pageBlockTable>
      
          </div>
   <div style="width:500px;margin: 10px auto 10px auto;">
   
      <apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">
      
         
       
         <apex:column headerValue="Ident" style="background:gray;">
            <apex:outputText value="{!wrapper.ident}"/>
         </apex:column>
         <apex:column headerValue="Master Code" style="background:gray;">
            <apex:inputField value="{!wrapper.acc.Entries_Code__c}"/>
         </apex:column>
         <apex:column headerValue="Amount" style="background:gray;">
            <apex:inputField value="{!wrapper.acc.Amount__c}"/>
         </apex:column>
 <apex:column headerValue="Related Account" style="background:gray;">
            <apex:inputField value="{!wrapper.acc.Related_Bank_Acc__c}"/>
         </apex:column>
         <apex:column headerValue="Narration" style="background:gray;">
            <apex:inputField value="{!wrapper.acc.Narration__c}"/>
         </apex:column>
          
       <apex:column headerValue="">
            <apex:commandButton value="Enter" action="{!addRows}" rerender="wtable" style="background:pink" >
         <apex:param name="addCount" value="1" assignTo="{!addCount}"/> 
      </apex:commandButton>
         </apex:column>
       
         <apex:column headerValue="Action">
            <apex:commandButton value="Delete" action="{!delWrapper}" rerender="wtable" style="background:Red">
               <apex:param name="toDelIdent" value="{!wrapper.ident}" assignTo="{!toDelIdent}"/> 
            </apex:commandButton>
         </apex:column>
         
      </apex:pageBlockTable>
     </div>
        
        
      <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable" style="width:100px;margin: 10px auto 10px auto;">
         <apex:param name="addCount" value="5" assignTo="{!addCount}"/> 
      </apex:commandButton>
      
      <apex:commandButton value="Save" action="{!save}" style="width:100px;margin: 10px auto 10px auto;"/>
   
    
     </apex:pageBlock>
 </apex:form>
  </div>
        </apex:define>
</apex:page>

I have added on Column which get the value for Related Account field.
SFDC DummySFDC Dummy
But Date and Payment Type Field not saved/inserted.how can its possible.