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 

Visualforce Error

Hi all
 
I have created a VF page where using two pageblock table on same object.requirment is i will be enter value in 1st page block table.and in second page block i will be created multiple record and when i am going to save its showing error...

Visualforce ErrorHelp for this Page
System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!save_close}' in component <apex:commandButton> in page newbankbook: Class.addrowCon.save_close: line 45, column 1
Class.addrowCon.save_close: line 45, column 1

 
<apex:page standardController="BankBook__c" extensions="addrowCon">
<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 >

   <apex:pageBlock title="New BankBook Entry:" >
    
        
      
       <Div align="right">
             <apex:inputText value="{!num}" style="width:45px"/>
             <apex:commandButton value="Add rows" action="{!add_rows}"/> 
       </Div>
       <br/>
       <div style="width:400px;">
       <apex:pageBlockTable value="{!accts1}" var="a1" id="table1">
          
          <apex:column headerValue="Date" style="background:gray;"  >
    <apex:inputField value="{!a1.Txn_Date__c}"/>
</apex:column>
 <apex:column headerValue="Payment Type" style="background:gray;">
    <apex:inputField value="{!a1.Credit_Debit__c}"/>
</apex:column>
 <apex:column headerValue="Company Account" style="background:gray;">
    <apex:inputField value="{!a1.Related_Bank_Acc__c}"/>
</apex:column>
      
       </apex:pageBlockTable>
       
       
        </div>
      
       
      <apex:pageBlockTable value="{!accts}" var="a" id="table">
         <apex:column headerValue="Master Code" style="background:gray;">
            <apex:inputField value="{!a.Entries_Code__c}"/>
         </apex:column>
         <apex:column headerValue="Master Name" style="background:gray;">
            <apex:inputField value="{!a.Debtor_Name__c}"/>
         </apex:column>
         <apex:column headerValue="Amount" style="background:gray;">
            <apex:inputField value="{!a.Amount__c}"/>
         </apex:column>
        
         <apex:column headerValue="Narration" style="background:gray;">
            <apex:inputField value="{!a.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:pageBlockTable>
        <apex:commandButton value="Save" action="{!save_close}" rerender="error"/>
   </apex:pageBlock>
    </apex:form>
    </div>
        </apex:define>
</apex:page>
 
public class addrowCon
{ 
    public addrowCon(ApexPages.StandardController controller) 
    
    
    {
   accts = new List<BankBook__c >(); 
     accts.add(new BankBook__c ()); 
     accts1 = new List<BankBook__c >(); 
     accts1.add(new BankBook__c ());  

    }


  public integer num { get; set; }
  public List<BankBook__c > combinedList {get; set;}
  public List<BankBook__c > accts {get; set;}
  public List<BankBook__c > accts1 {get; set;} 
  public static Integer addCount {get; set;}
  private Integer nextIdent=1;
 
   public PageReference add_rows() {
    for(integer i=0;i<num ;i++)
        {
          accts.add(new BankBook__c ());    
        }
        
        return null;
     }
 public void addRows()
 {
  for (Integer idx=0; idx<addCount; idx++)
  {
   accts.add(new BankBook__c());
  }
 }    
     
     
     
     
     
  public PageReference save_close()
  {       
        
  insert combinedList;
        
     PageReference home = new PageReference('/home/home.jsp');
     home.setRedirect(true);
     return home;
  }
}

User-added image
Shrikant BagalShrikant Bagal
Hello Project Dummy,

As per your code you were trying to insert null list i.e (combinedList) as its not used in VF its not get any record and when you try to save button code insert null list.

Please check code.

Thanks!
SFDC DummySFDC Dummy
How to resolve it...
Amit Chaudhary 8Amit Chaudhary 8
Please try below code. I hope that will help u
public class addrowCon
{ 
    public addrowCon(ApexPages.StandardController controller) 
    
    
    {
   accts = new List<BankBook__c >(); 
     accts.add(new BankBook__c ()); 
     accts1 = new List<BankBook__c >(); 
     accts1.add(new BankBook__c ());  

    }


  public integer num { get; set; }
  public List<BankBook__c > combinedList {get; set;}
  public List<BankBook__c > accts {get; set;}
  public List<BankBook__c > accts1 {get; set;} 
  public static Integer addCount {get; set;}
  private Integer nextIdent=1;
 
   public PageReference add_rows() {
    for(integer i=0;i<num ;i++)
        {
          accts.add(new BankBook__c ());    
        }
        
        return null;
     }
 public void addRows()
 {
  for (Integer idx=0; idx<addCount; idx++)
  {
   accts.add(new BankBook__c());
  }
 }    
     
     
     
     
     
  public PageReference save_close()
  {       
	if(accts1.size()>0)
	{	
		insert accts1;
	}
	if(accts.size() > 0)
	{
		insert accts;
	}
		//insert combinedList;
        
     PageReference home = new PageReference('/home/home.jsp');
     home.setRedirect(true);
     return home;
  }
}

Please let us know if this will help you

Thanks
Amit Chaudhary
SFDC DummySFDC Dummy
Same 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: [Entries Code]: [Entries Code] Error is in expression '{!save_close}' in component in page newbankbook: Class.addrowCon.save_close: line 46, column 1 Class.addrowCon.save_close: line 46, column 1