I need a best way to avoid the object reference between two list. For example, I have list of Contact
records and I create one more list in which I make the changes to each record's LastName
. My problem is, if I make changes in new list, the first list last name also changes. Here is my code.
list<contact> cont = new List<contact>([select id, lastName from contact where lastname Like '%xyz%' Limit 3]);
list<Contact> editedCont = new List<Contact>();
editedCont.addAll(cont);
for(contact c: editedCont)
c.lastname = 'abc';
System.debug(cont);
System.debug(editedcont);