+ Start a Discussion
KyoKyo 

Copy Record

I can't copy data from the first record to secord Record when AddRow. 


 

 

public class MassCreatetion{
    public List<Case> Cases {get; set;}
    
    public MassCreatetion(){
        Cases = new List<Case>();
        Case CaseAdd = new Case();
        
        if(Apexpages.Currentpage().getParameters().get('ID')!=null) {
            CaseAdd.ContactID = (id)Apexpages.Currentpage().getParameters().get('id');
        }
      
        //accts.add(new Opportunities_Line_Item__c());
        Cases.add(CaseAdd);
        
    }
    public void addrow(){
        Case CaseAdd = new Case();
        
        if(Apexpages.Currentpage().getParameters().get('ID')!=null) {
            CaseAdd.ContactID = (id)Apexpages.Currentpage().getParameters().get('id');
        }
         Cases.add(CaseAdd);
        //accts.add(new Opportunities_Line_Item__c());
    }
   public PageReference deleteRow() {
   if (cases.size()>1)
   {
      cases.remove(Cases.size()-1);
   }
 return null;
 }
    public PageReference save(){
        insert Cases;
        PageReference home = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        home.setRedirect(true);
        return home;
    }
    public PageReference Cancel() {
        PageReference returnPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        returnPage.setRedirect(true);
        return returnPage;
    }
    }

 

Thank you so much.

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Are you simply looking to copy the details from the previous row in the table?

 

If so, you should be able to clone it to create the new one.  Something like:

 

 

public void addrow(){
        Case CaseAdd;
        if (cases.size()>0)
        {
           caseAdd=cases[cases.size()-1].clone(false, true);
        }
        else
        {
           CaseAdd=new Case();
           if(Apexpages.Currentpage().getParameters().get('ID')!=null)    {
              CaseAdd.ContactID = (id)Apexpages.Currentpage().getParameters().get('id');
           }
         }
         Cases.add(CaseAdd);
        //accts.add(new Opportunities_Line_Item__c());
    }

 

 

All Answers

bob_buzzardbob_buzzard

Are you simply looking to copy the details from the previous row in the table?

 

If so, you should be able to clone it to create the new one.  Something like:

 

 

public void addrow(){
        Case CaseAdd;
        if (cases.size()>0)
        {
           caseAdd=cases[cases.size()-1].clone(false, true);
        }
        else
        {
           CaseAdd=new Case();
           if(Apexpages.Currentpage().getParameters().get('ID')!=null)    {
              CaseAdd.ContactID = (id)Apexpages.Currentpage().getParameters().get('id');
           }
         }
         Cases.add(CaseAdd);
        //accts.add(new Opportunities_Line_Item__c());
    }

 

 

This was selected as the best answer
KyoKyo

Thank Bob Perfect! 

You are my good friends.