I have a custom object that I want the user to edit, but before editing, I want to make a backup of the object that can be used to restore if necessary.
Basically, the user will have ObjectA that has all the information they need, they click Edit, a backup of ObjectA is created as ObjectB, the user can make changes to ObjectA, and then the user can hit cancel to discard any changes made to ObjectA which essentially just replaces ObjectA with the backup object, ObjectB.
What's the best way to make a new object instead of simply creating another reference to the object?
// User has their main object
CustomObject obj = new CustomObject();
// User clicks Edit and a copy of the object is stored in case obj needs to be restored
CustomObject backupObj = obj; // This only creates a reference but I'm not sure how else to show this
// User makes changes to obj but decides to discard those changes and clicks Cancel
obj = backupObj; // obj is restored
// User goes on with the program