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.ListException: DML statment found null SObject at position 0

Hi All

I am facing error in my Apex code .Like

Visualforce ErrorHelp for this Page
System.ListException: DML statment found null SObject at position 0
Error is in expression '{!savebook}' in component <apex:commandButton> in page try2: Class.MultiAdd11.savebook: line 25, column 1
Class.MultiAdd11.savebook: line 25, column 1




Pls help me....

VF Page
-------------
<apex:page StandardController="BankBook__c" extensions="MultiAdd11" id="thePage" sidebar="false" showHeader="false">
 <apex:define name="body">
            
            <div style="width:1000px;margin: 10px auto 10px auto;">
             <apex:image id="theImage" value="{!$Resource.Emami}" width="100" height="100"/>
<apex:form >
 
          
 
 
        <apex:pageblock id="pb1" title="Book Entry Form"> 
        
        
 <b>Transcation Date:</b><apex:inputfield value="{!Con1.Txn_Date__c}"/><br/> 
        
    <apex:outputPanel id="panel">

            <apex:outputText value="{!Con1.Txn_Date__c}"/>

    </apex:outputPanel>
                                    
 
                <apex:pageblocktable value="{!lstInner}" var="e1" id="therepeat">
 
                   <apex:column >
 
                    <apex:facet name="header">Debtor Code</apex:facet>
 
                     <apex:inputfield value="{!e1.con.Entries_Code__c}"/>
 
                   </apex:column>
 
                   <apex:column >
 
                   <apex:facet name="header"> Debtor Name</apex:facet>
 
                     <apex:inputtext value="{!e1.con.Debtor_Name__c}"/>
 
                   </apex:column>
 
                   <apex:column >
 
                   <apex:facet name="header">Payment Type</apex:facet>
 
                     <apex:inputfield value="{!e1.con.Credit_Debit__c}"/>
 
                   </apex:column>
 
                   <apex:column >
 
                   <apex:facet name="header">Amount</apex:facet>
 
                     <apex:inputfield value="{!e1.con.Amount__c}"/>
 
                   </apex:column>
                   <apex:column >
 
                   <apex:facet name="header">Narration</apex:facet>
 
                     <apex:inputfield value="{!e1.con.Narration__c}"/>
 
                   </apex:column>
                   
                   
                    <apex:column >
 
                   <apex:facet name="header">Add</apex:facet>
 
                     <apex:commandButton value="+" action="{!Add}" rerender="pb1"/> 
 
                   </apex:column>
 
                   <apex:column >
 
                   <apex:facet name="header">Del</apex:facet>
 
                      <apex:commandButton value="X" action="{!Del}" rerender="pb1">
 
                        <apex:param name="rowToBeDeleted" value="{!e1.recCount}" assignTo="{!selectedRowIndex}"></apex:param>
 
                        </apex:commandButton>
 
                   </apex:column>
 
                  
 
                </apex:pageblocktable>                
 
           

 
    <apex:pageBlockButtons location="bottom">        
 
        <apex:commandbutton value="SUBMIT" action="{!savebook}"/>
         <apex:commandbutton value="PREVIEW" />
          <apex:commandbutton value="CANCEL" />
 
    </apex:pageBlockButtons>  
</apex:pageblock>
 
</apex:form>
 </div>
        </apex:define>
        <apex:form >
        <apex:pageBlock title="Entry List">
                    
       
        </apex:pageBlock>
        </apex:form>
</apex:page>

Apex Class
---------------
public class MultiAdd11{    
 
    public List<BankBook__c>lstAcct  = new List<BankBook__c>();
 
    public List<innerClass> lstInner{get;set;}
 
    public String selectedRowIndex{get;set;} 
    public List<BankBook__c> lst{get;set;} 
    public BankBook__c Con1 { get; set; }
 
    public Integer count = 1;
 
                
 
    public PageReference savebook(){
 
        PageReference pr = new PageReference('/apex/Try2');        
 
        for(Integer j = 0;j<lstInner.size();j++){
 
            lstAcct.add(lstInner[j].acct);
 
        } 
 
        upsert lstAcct;
 
        pr.setRedirect(True);
 
        return pr;
 
    }
 
         
 
    public void Add(){   
 
        count = count+1;
 
        addMoreRows();      
 
    }
 
     
 
    public void addMoreRows(){      
 
      innerClass objInnerClass = new innerClass(count);
 
      lstInner.add(objInnerClass);          
 
    }
 
     
 
    public void Del(){      
 
      lstInner.remove(Integer.valueOf(selectedRowIndex)-1);
 
      count = count - 1;        
 
    }
    
    
     
                 
 
    public MultiAdd11(ApexPages.StandardController ctlr){    
 
       lstInner = new List<innerClass>();
 
       addMoreRows();
 
       selectedRowIndex = '0';   
       Con1 = new BankBook__c();     
 lst=[select id,Entries_Code__c,Debtor_Name__c,Credit_Debit__c,Amount__c from BankBook__c];
    }
 public PageReference refresh() {
        return null;
    }

  
    public class innerClass{               
 
        public String recCount{get;set;}                
 
        public BankBook__c acct{get;set;}
 
        
 
        Public BankBook__c con{get;set;}
 
        public innerClass(Integer intCount){
 
            recCount = String.valueOf(intCount);                                
 
            con = new BankBook__c();            
 
        }
 
    }
 
}

 
Shrikant BagalShrikant Bagal
Please replace your "savebook" Method with following Method

 
public PageReference savebook(){
 
        PageReference pr = new PageReference('/apex/Try2');        
 
        for(Integer j = 0;j<lstInner.size();j++){
 
            lstAcct.add(lstInner[j].acct);
 
        } 
 
      if(lstAcct != null && !lstAcct.isEmpty()){
                       upsert lstAcct;
      }
 
        pr.setRedirect(True);
 
        return pr;
 
    }

If its helps, please mark as best answer so it will help to other who will serve same problem.
​Thanks!
SFDC DummySFDC Dummy
its showing same error like System.ListException: DML statment found null SObject at position 0 Error is in expression '{!savebook}' in component in page try2: Class.MultiAdd11.savebook: line 26, column 1 Class.MultiAdd11.savebook: line 26, column 1
Shrikant BagalShrikant Bagal
Please try following

 
public PageReference savebook(){
 
        PageReference pr = new PageReference('/apex/Try2');        
 
        for(Integer j = 0;j<lstInner.size();j++){
            if(lstInner[j].acct != null){
                  lstAcct.add(lstInner[j].acct);
             }
        } 
 
      if(lstAcct != null && !lstAcct.isEmpty()){
                       upsert lstAcct;
      }
 
        pr.setRedirect(True);
 
        return pr;
 
    }


If its helps, please mark as best answer so it will help to other who will serve same problem.
​Thanks!
 
SFDC DummySFDC Dummy
record not saved
Usman AslamUsman Aslam
Please initialize acct variable in your innerClass constructor.

Thanks
Amit Chaudhary 8Amit Chaudhary 8
Please try below code:-
public class MultiAdd11{    
 
    public List<BankBook__c>lstAcct  = new List<BankBook__c>();
 
    public List<innerClass> lstInner{get;set;}
 
    public String selectedRowIndex{get;set;} 
    public List<BankBook__c> lst{get;set;} 
    public BankBook__c Con1 { get; set; }
 
    public Integer count = 1;
 
                
 
	public PageReference savebook()
	{
        PageReference pr = new PageReference('/apex/Try2');        
        for(Integer j = 0;j<lstInner.size();j++)
		{
            if( lstInner[j].acct != null )
			{
                  lstAcct.add(lstInner[j].acct);
            }
        } 
 
		if(lstAcct != null && !lstAcct.isEmpty())
		{
                       upsert lstAcct;
		}
        pr.setRedirect(True);
        return pr;
    } 
         
 
    public void Add(){   
 
        count = count+1;
 
        addMoreRows();      
 
    }
 
     
 
    public void addMoreRows(){      
 
      innerClass objInnerClass = new innerClass(count);
 
      lstInner.add(objInnerClass);          
 
    }
 
     
 
    public void Del(){      
 
      lstInner.remove(Integer.valueOf(selectedRowIndex)-1);
 
      count = count - 1;        
 
    }
    
    
     
                 
 
    public MultiAdd11(ApexPages.StandardController ctlr)
	{    
 
       lstInner = new List<innerClass>();
 
       addMoreRows();
 
       selectedRowIndex = '0';   
       Con1 = new BankBook__c();     
		lst=[select id,Entries_Code__c,Debtor_Name__c,Credit_Debit__c,Amount__c from BankBook__c];
    }
	
	public PageReference refresh() 
	{
        return null;
    }

  
    public class innerClass
	{               
        public String recCount{get;set;}                
        public BankBook__c acct{get;set;}
        Public BankBook__c con{get;set;}
 
        public innerClass(Integer intCount)
		{
            recCount = String.valueOf(intCount);                                
            con = new BankBook__c();
			acct = 	new BankBook__c();		
        }
 
    }
 
}

Please mark this as solution if this will help you.

Thanks,
Amit Chaudhary