• sfdclearner123
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
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 - 
 
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();
        }
    }

}


User-added image
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 - 
 
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();
        }
    }

}


User-added image