You need to sign in to do that
Don't have an account?
SirTrav
Copy wrapper class
I have a wrapper class that has a number of objects in it. I then have a list of that class that is displayed on a visualforce page. what I want to do is take the initial list and copy it and put it in a second list. Then I want to be able to edit the first list without the second list being changed. Here is what the code looks like the one below but I have shortened the code by removing some standard stuff and puting ...... in its place. what I am trying to do is leave the original list in place on the visualforce page to be edited and added back to the second list with slightly different answers. The problem is that when the original list is changed it changes the second list.
public void runAtStart(){ MwList = new list<MyWrapper>(); OpportunityLineItem o = new OpportunityLineItem(); o.opportunityid = ......... MyWrapper mw = new MyWrapper(); mw.oli = ....... MwList.add(mw); } public class MyWrapper{ public opportunitylineitem oli {get;set;} public string s {get;set;} public integer i {get;set;} } public list<MyWrapper> MwList {get;set;} public list<MyWrapper> WrapperList2 {get;set;} public void ToSecondList(){ if(WrapperList2 == null){ WrapperList2 = new list<MyWrapper>(); } for(MyWrapper m : MwList){ MyWrapper w = new MyWrapper(); w = m.clone(); WrapperList2.add(w); } } }
NOTE: This code has not been tested and may contain typographical or logical errors.
You may need to adjust the booleans on the .clone(..) method on the oli, but that should be a start.
I get this for oldList
and this for newList
which is expected