You need to sign in to do that
Don't have an account?
nihar
error message:
Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Last Name]: [Last Name]
Error is in expression '{!save}' in component <apex:commandButton> in page formexample: Class.EnrollmentFormClass.save: line 30, column 1
An unexpected error has occurred. Your development organization has been notified.
visualforcepage :
<apex:page controller="EnrollmentFormClass">
<apex:form >
<apex:pageBlock title="Opportunitiy Zone Enrollment Form">
<apex:pageBlockSection columns="3">
<apex:inputField value="{!con.Student_Name__c}"/>
<apex:inputField value="{!con.School__c}"/>
<apex:inputField value="{!con.Date__c}"/>
</apex:pageBlockSection>
<br/>
<br/>
SPARC programs are funded by United Way of Greater Atlanta. As such, we are required to report demographic, income, educational and health access information on every individual/family we serve. With the United Way belief that serving one family member serves them all, we collect general information on each member of your household. We appreciate your willingness to complete this form in its entirety so that we can continue providing free programs to the community. Thank you!
<br/>
<br/>
<apex:pageBlockSection title="Head of Household Information:">
<apex:inputField value="{!con.FirstName}"/>
<apex:inputField value="{!con.LastName}"/>
<apex:inputField value="{!con.Date_of_Birth__c}"/>
<apex:inputField value="{!con.Gender__c}"/>
<apex:inputField value="{!con.Do_you_have_a_primary_medical_provider__c}"/>
<apex:inputField value="{!con.Do_you_have_a_primary_medical_provider__c}"/>
<apex:inputField value="{!con.Address__c}"/>
<apex:inputField value="{!con.City__c}"/>
<apex:inputField value="{!con.State__c}"/>
<apex:inputField value="{!con.County__c}"/>
<apex:inputField value="{!con.Phone__c}"/>
<apex:inputField value="{!con.Email_Address__c}"/>
<apex:inputField value="{!con.Preferred_Method_of_Contact_Circle_One__c}"/>
</apex:pageBlockSection>
<apex:pageBlocksection title="Demographic Data: (All information is confidential and is used in applying for grants to fund this program.)" columns="3">
<apex:inputField value="{!con.Spanish_translation_Services_Needed__c}"/>
<apex:inputField value="{!con.Race_Check_One__c}"/>
<apex:inputField value="{!con.Marital_Status_check_one__c}"/>
<apex:inputField value="{!con.HIGHEST_LEVEL_OF_EDUCATION_Check_one__c}"/>
<apex:inputField value="{!con.Employment_check_one__c}"/>
</apex:pageBlocksection>
<apex:pageBlocksection title="Income:" columns="3">
<apex:inputField value="{!con.Annual_Income__c}"/>
<apex:inputField value="{!con.Source_of_Income__c}"/>
<apex:inputField value="{!con.Primary_Method_of_Transportation__c}"/>
</apex:pageBlocksection>
<apex:pageBlocksection title="HOUSEHOLD Information:" columns="3">
<apex:inputField value="{!conc.Other_Adult_First_Name__c}"/>
<apex:inputField value="{!conc.LastName}"/>
<apex:inputField value="{!conc.Date_of_Birth__c}"/>
<apex:inputField value="{!conc.Gender__c}"/>
<apex:inputField value="{!conc.Relationship_Primary_Care_Provider__c}"/>
<apex:inputField value="{!conc.Medical_Insurance__c }"/>
</apex:pageBlocksection>
<apex:pageBlockButtons location="bottom" >
<apex:commandButton action="{!save}" value="save"/>
</apex:pageBlockButtons>
<apex:pageBlocksection title="Children (all children currently in your household, INCLUDING those participating in this program):" columns="1">
<apex:pageBlockTable value="{!concAddList}" var="c">
<apex:column headerValue="Name">
<apex:commandButton action="{!AddRow}" value="AddRow"/>
</apex:column>
<apex:column headerValue="Name">
<apex:inputfield value="{!c.LastName}"/>
</apex:column>
<apex:column headerValue="Date of Birth">
<apex:inputfield value="{!c.Date_of_Birth__c}"/>
</apex:column>
<apex:column headerValue="Gender">
<apex:inputfield value="{!c.Gender__c}"/>
</apex:column>
<apex:column headerValue="Relationship Primary Care Provider">
<apex:inputfield value="{!c.Relationship_Primary_Care_Provider__c}"/>
</apex:column>
<apex:column headerValue="Medical Insurance}">
<apex:inputfield value="{!c.Medical_Insurance__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlocksection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex class :
public with sharing class EnrollmentFormClass {
public Contact con {get;set;}
public Contact conc {get;set;}
public Contact conct {get;set;}
public List<Contact> concAddList{get;set;}
public Account acc {get;set;}
public EnrollmentFormClass() {
con = new Contact();
conc = new Contact();
conct = new Contact();
acc = new Account();
concAddList = new List<Contact>();
concAddList.add(con);
}
public void AddRow(){
concAddList.add(new Contact());
concAddList.add(con);
}
public void save(){
insert con;
acc.name = con.lastName;
insert acc;
con.AccountId = acc.Id;
conc.AccountId = acc.Id;
conct.AccountId = acc.Id;
insert conc;
insert conct;
insert concAddList;
update con;
}
}
Error is in expression '{!save}' in component <apex:commandButton> in page formexample: Class.EnrollmentFormClass.save: line 30, column 1
An unexpected error has occurred. Your development organization has been notified.
visualforcepage :
<apex:page controller="EnrollmentFormClass">
<apex:form >
<apex:pageBlock title="Opportunitiy Zone Enrollment Form">
<apex:pageBlockSection columns="3">
<apex:inputField value="{!con.Student_Name__c}"/>
<apex:inputField value="{!con.School__c}"/>
<apex:inputField value="{!con.Date__c}"/>
</apex:pageBlockSection>
<br/>
<br/>
SPARC programs are funded by United Way of Greater Atlanta. As such, we are required to report demographic, income, educational and health access information on every individual/family we serve. With the United Way belief that serving one family member serves them all, we collect general information on each member of your household. We appreciate your willingness to complete this form in its entirety so that we can continue providing free programs to the community. Thank you!
<br/>
<br/>
<apex:pageBlockSection title="Head of Household Information:">
<apex:inputField value="{!con.FirstName}"/>
<apex:inputField value="{!con.LastName}"/>
<apex:inputField value="{!con.Date_of_Birth__c}"/>
<apex:inputField value="{!con.Gender__c}"/>
<apex:inputField value="{!con.Do_you_have_a_primary_medical_provider__c}"/>
<apex:inputField value="{!con.Do_you_have_a_primary_medical_provider__c}"/>
<apex:inputField value="{!con.Address__c}"/>
<apex:inputField value="{!con.City__c}"/>
<apex:inputField value="{!con.State__c}"/>
<apex:inputField value="{!con.County__c}"/>
<apex:inputField value="{!con.Phone__c}"/>
<apex:inputField value="{!con.Email_Address__c}"/>
<apex:inputField value="{!con.Preferred_Method_of_Contact_Circle_One__c}"/>
</apex:pageBlockSection>
<apex:pageBlocksection title="Demographic Data: (All information is confidential and is used in applying for grants to fund this program.)" columns="3">
<apex:inputField value="{!con.Spanish_translation_Services_Needed__c}"/>
<apex:inputField value="{!con.Race_Check_One__c}"/>
<apex:inputField value="{!con.Marital_Status_check_one__c}"/>
<apex:inputField value="{!con.HIGHEST_LEVEL_OF_EDUCATION_Check_one__c}"/>
<apex:inputField value="{!con.Employment_check_one__c}"/>
</apex:pageBlocksection>
<apex:pageBlocksection title="Income:" columns="3">
<apex:inputField value="{!con.Annual_Income__c}"/>
<apex:inputField value="{!con.Source_of_Income__c}"/>
<apex:inputField value="{!con.Primary_Method_of_Transportation__c}"/>
</apex:pageBlocksection>
<apex:pageBlocksection title="HOUSEHOLD Information:" columns="3">
<apex:inputField value="{!conc.Other_Adult_First_Name__c}"/>
<apex:inputField value="{!conc.LastName}"/>
<apex:inputField value="{!conc.Date_of_Birth__c}"/>
<apex:inputField value="{!conc.Gender__c}"/>
<apex:inputField value="{!conc.Relationship_Primary_Care_Provider__c}"/>
<apex:inputField value="{!conc.Medical_Insurance__c }"/>
</apex:pageBlocksection>
<apex:pageBlockButtons location="bottom" >
<apex:commandButton action="{!save}" value="save"/>
</apex:pageBlockButtons>
<apex:pageBlocksection title="Children (all children currently in your household, INCLUDING those participating in this program):" columns="1">
<apex:pageBlockTable value="{!concAddList}" var="c">
<apex:column headerValue="Name">
<apex:commandButton action="{!AddRow}" value="AddRow"/>
</apex:column>
<apex:column headerValue="Name">
<apex:inputfield value="{!c.LastName}"/>
</apex:column>
<apex:column headerValue="Date of Birth">
<apex:inputfield value="{!c.Date_of_Birth__c}"/>
</apex:column>
<apex:column headerValue="Gender">
<apex:inputfield value="{!c.Gender__c}"/>
</apex:column>
<apex:column headerValue="Relationship Primary Care Provider">
<apex:inputfield value="{!c.Relationship_Primary_Care_Provider__c}"/>
</apex:column>
<apex:column headerValue="Medical Insurance}">
<apex:inputfield value="{!c.Medical_Insurance__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlocksection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex class :
public with sharing class EnrollmentFormClass {
public Contact con {get;set;}
public Contact conc {get;set;}
public Contact conct {get;set;}
public List<Contact> concAddList{get;set;}
public Account acc {get;set;}
public EnrollmentFormClass() {
con = new Contact();
conc = new Contact();
conct = new Contact();
acc = new Account();
concAddList = new List<Contact>();
concAddList.add(con);
}
public void AddRow(){
concAddList.add(new Contact());
concAddList.add(con);
}
public void save(){
insert con;
acc.name = con.lastName;
insert acc;
con.AccountId = acc.Id;
conc.AccountId = acc.Id;
conct.AccountId = acc.Id;
insert conc;
insert conct;
insert concAddList;
update con;
}
}
In your Save method please assign some value to Contact.LastName field. Your Insert is failing because LastName field is required on COntact.
Please mark as best answer if helped.
Regards,
Ramakant
All Answers
In your Save method please assign some value to Contact.LastName field. Your Insert is failing because LastName field is required on COntact.
Please mark as best answer if helped.
Regards,
Ramakant
how to assign some value to Contact.LastName field?
Regards,
Ramakant
My task is to create page block table in application form by using visualforce and apex classes and insert data into it after inserting when click on addrow button it must open a new row
I had worked on similar requirement in the past to add new row for attachment. Please find below code for the same:
addMore method in above controller would do the trick for you.
PLease let me know if helped by marking best answer.
Regards,
Ramakant