You need to sign in to do that
Don't have an account?
nihar
how to addrow by using addrow button in apexclass
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(){
conct = new Contact();
concAddList.add(conct);
//concAddList.add(new Contact());
}
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;
}
}
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="{!conct}" 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>
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(){
conct = new Contact();
concAddList.add(conct);
//concAddList.add(new Contact());
}
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;
}
}
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="{!conct}" 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>
This is a dummy code I guess you can add the fields name accordingly to your requirement
You have to replace your pageblocktable by this:
In Controller Add these methods And Change the codes Accordingly
Mark this thread as close if the issue has been resolved
All Answers
https://developer.salesforce.com/forums?id=9060G0000005SzrQAE
when i open the link it opening the same page
you can rerender the page after click on addrow button
Regards
Shailesh Rawte
There are a lot of links present for this
If then also you face error do tell me
http://www.forcetree.com/2015/03/dynamically-addremove-rows-from-table.html
http://sfdcsrini.blogspot.com/2014/12/adding-and-deleting-rows-dynamically-in.html
can u spend some time for my code and get the output
This is a dummy code I guess you can add the fields name accordingly to your requirement
You have to replace your pageblocktable by this:
In Controller Add these methods And Change the codes Accordingly
Mark this thread as close if the issue has been resolved