function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
StaciStaci 

Add Row Save functionality not creating new records

I have some code I found on here to create "Add Row" functionality.  Everything seems to work except the Save button.  Its not creating the new records. 

What should happen is on a Subscription record, I have an embedded apex page to add Subscription Asset (which is a related list on the Subscritpion record).  I want to be able to add multiple rows of the Subscription Asset and save them to the related list on the current Subscription record.  What happens when I click Save, it refreshs, blanks out the fields in the embedded apex page and doesn't save any of the Subscription Asset records anywhere.  
public class MultiAdd {
public String currentRecordId {get;set;}
    //will hold the Subscription Asset records to be saved
    public List<Subscription_Assets__c>lstAsset = new List<Subscription_Assets__c>();

    //list of the inner class
    public List<innerClass> lstInner
    {get;set;}

    //will indicate the row to be deleted
    public String selectedRowIndex
    {get;set;} 
   
   
    Public Support_Subscription__c ss
    {get;set;}

    Public Subscription_Assets__c sa
    {get;set;}
    
    //no. of rows added/records in the inner class list
    public Integer count = 1;
    

    
//save the records by adding the elements in the inner class list to lstAsset,return to the same page
public PageReference Save()
    {
         
        PageReference pr = new PageReference('/apex/CW_Support_Subscription');
      
         // Fill in the values for the new record
    //lstAsset = new List<Subscription_Assets__c>();
  for(Subscription_Assets__c sa : lstAsset)      
     {   
        for(Integer j = 0;j<lstInner.size();j++)
        {
           
           //Subscription_Assets__c sa = lstInner.asset;
            lstAsset.add(lstInner[j].asset);

          }  
        }

        insert lstAsset;
        pr.setRedirect(True);
        return pr;
    }


    //add one more row
    public void Add()
    {  
        count = count+1;
        addMore();     
    }

    /*Begin addMore*/
    public void addMore()
    {
        //call to the inner class constructor
        innerClass objInnerClass = new innerClass(count);

        //add the record to the inner class list
        lstInner.add(objInnerClass);   
        system.debug('lstInner---->'+lstInner);           
    }/* end addMore*/


    /* begin delete */
    public void Del()
    {
        system.debug('selected row index---->'+selectedRowIndex);
        lstInner.remove(Integer.valueOf(selectedRowIndex)-1);
        count = count - 1;
    }/*End del*/


    /*Constructor*/
    public MultiAdd(ApexPages.StandardController ctlr)
    {
        currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        lstInner = new List<innerClass>();
        addMore();
        selectedRowIndex = '0';
    }/*End Constructor*/



    /*Inner Class*/
    public class innerClass
    {      
        /*recCount acts as a index for a row. This will be helpful to identify the row to be deleted */
        public String recCount
        {get;set;}

        public Subscription_Assets__c asset
        {get;set;}
              

        /*Inner Class Constructor*/
        public innerClass(Integer intCount)
        {
            recCount = String.valueOf(intCount);       
         
            /*create a new Asset*/
            asset = new Subscription_Assets__c();
        }/*End Inner class Constructor*/   

    }/*End inner Class*/
}/*End Class*/

 
SuredreamSuredream
Can you try using rerender attribute on your apex:commandbutton ?