You need to sign in to do that
Don't have an account?
sfdclearner123
Add dynamic Rows in vf page is clearing previous rows values
I am having this below code in which i am trying to add dynamic rows. But when i click add Contact Email button it is clearing the previous rows.
Below Method is called from add Contact Email button.
addContactEmail()
Apex Class -
Below Method is called from add Contact Email button.
addContactEmail()
Apex Class -
public class accountcontactwrapperclass { public Account acc {get;set;} public List<ContactWrapper> contactWrapperlist {get;set;} public List<Contact> cList; public String wrapperId {get; set;} public accountcontactwrapperclass (ApexPages.StandardController controller){ contactWrapperlist = new List<ContactWrapper>(); acc = new Account(); cList = new List<Contact>(); addContact(); } public void addContact(){ ContactWrapper contWrap = new ContactWrapper(); ContactEmail contactEmailwrap = new ContactEmail(); contWrap.contactEmails.add(contactEmailwrap); contactWrapperlist.add(contWrap); } public void addContactEmail(){ for(ContactWrapper s : contactWrapperlist){ if(s.wrapperId == wrapperId){ s.contactEmails.add(new ContactEmail()); } } } public class ContactEmail{ public Contact c1 {get;set;} } public class ContactWrapper{ public Contact c {get;set;} public string wrapperId {get;set;} public List<ContactEmail> contactEmails {get;set;} public ContactWrapper(){ Blob b = Crypto.GenerateAESKey(128); String h = EncodingUtil.ConvertTohex(b); wrapperId = h.SubString(0,8)+ '-' + h.SubString(8,12) + '-' + h.SubString(12,16) + '-' + h.SubString(16,20) + '-' + h.substring(20); contactEmails = new List<ContactEmail>(); c = new Contact(); } } }
I don't know how your vf page looks like, so I am not sure from where you are calling this method.
But usually the previous values are cleared out, when the list is initialized, during your call. So in your case, the accountwrapper() constructor is called each time, and the list is initialized, and then the addContactEmail is called.
Try adding a debug line at the constructor to see if it gets called each time the button is clicked, or try a debug line with contactWrapperlist.size() to confirm this.
You can change your code accordingly then.
Hope that helps
Can you check and let me know.