You need to sign in to do that
Don't have an account?
SFDC Dummy
System.DmlException
Hi All
I am facing problem saving record from two pageblock table in a single vf page
error
------------
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_close}' in component <apex:commandButton> in page newbankbook: Class.addrowCon.save_close: line 22, column 1
Class.addrowCon.save_close: line 22, column 1
I am facing problem saving record from two pageblock table in a single vf page
error
------------
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_close}' in component <apex:commandButton> in page newbankbook: Class.addrowCon.save_close: line 22, column 1
Class.addrowCon.save_close: line 22, column 1
public class addrowCon { public integer num { get; set; } public List<BankBook__c > accts {get; set;} public List<BankBook__c > accts1 {get; set;} public addrowCon() { accts = new List<BankBook__c >(); accts.add(new BankBook__c ()); accts1 = new List<BankBook__c >(); accts1.add(new BankBook__c ()); } public PageReference add_rows() { for(integer i=0;i<num ;i++) { accts.add(new BankBook__c ()); } return null; } public PageReference save_close() { insert accts; insert accts1; PageReference home = new PageReference('/home/home.jsp'); home.setRedirect(true); return home; } }
<apex:page controller="addrowCon" > <apex:form > <apex:sectionHeader title="flexandsalesforceblog" subtitle="AddRows" help="Http://flexandsalesforce.blogspot.com"/> <apex:pageBlock title="Add row Dynamically" > <apex:pageBlockButtons location="bottom"> <apex:commandButton value="Save" action="{!save_close}" rerender="error"/> </apex:pageBlockButtons> <Div align="right"> <apex:inputText value="{!num}" style="width:45px"/> <apex:commandButton value="Add rows" action="{!add_rows}"/> </Div> <br/> <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> <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="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:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
accts is inserting first so acct1 is giving Error.
List<BankBook__c> combinedList = New List<BankBook__c>();
combinedList.Addall(accts1);
combinedList.Addall(accts);
public PageReference save_close()
{
insert combinedList;
PageReference home = new PageReference('/home/home.jsp');
home.setRedirect(true);
return home;
}
Class.addrowCon.<init>: line 14, column 1
Please use below code I have Executed in my org. it is working fine.
Make sure before inserting give all mandatory fileds. otherwise you wil get Same Error.
VF Code:
<apex:page controller="addrowCon" >
<apex:form >
<apex:sectionHeader title="flexandsalesforceblog" subtitle="AddRows" help="Http://flexandsalesforce.blogspot.com"/>
<apex:pageBlock title="Add row Dynamically" >
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Save" action="{!save_close}"/>
</apex:pageBlockButtons>
<Div align="right">
<apex:inputText value="{!num}" style="width:45px"/>
<apex:commandButton value="Add rows" action="{!add_rows}"/>
</Div>
<br/>
<apex:pageBlockTable value="{!accts1}" var="a1" id="table1">
<apex:column headerValue="OpportunityName" style="background:gray;" >
<apex:inputField value="{!a1.name}"/>
</apex:column>
<apex:column headerValue="Stage Name" style="background:gray;">
<apex:inputField value="{!a1.StageName}"/>
</apex:column>
<apex:column headerValue="Date" style="background:gray;">
<apex:inputField value="{!a1.closeDate}"/>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockTable value="{!accts}" var="a" id="table">
<apex:column headerValue="Opportunity name" style="background:gray;">
<apex:inputField value="{!a.name}"/>
</apex:column>
<apex:column headerValue="Probability" style="background:gray;">
<apex:inputField value="{!a.StageName}"/>
</apex:column>
<apex:column headerValue="Dtae" style="background:gray;">
<apex:inputField value="{!a.closeDate}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class addrowCon
{
public integer num { get; set; }
public List<opportunity > accts {get; set;}
public List<opportunity > accts1 {get; set;}
public List<Opportunity> combinedList = New List<Opportunity>();
public addrowCon()
{
accts = new List<opportunity >();
accts.add(new opportunity ());
accts1 = new List<opportunity >();
accts1.add(new opportunity ());
}
public Pagereference add_rows() {
for(Integer i=0;i<num;i++){
accts.add(new Opportunity());
}
return null;
}
public PageReference save_close()
{
combinedList.Addall(accts1);
combinedList.Addall(accts );
insert combinedList;
PageReference home = new PageReference('/home/home.jsp');
home.setRedirect(true);
return home;
}
}
Regards
Satish Atla