I've noticed that when I assign an object returned by map.get(key)
, the changes that I've done to the new object reflect in the original one(which is in the map). Is it returns a reference? Sorry I couldn't able to find a solid explanation for this. Also what about the other collections? Below is the sample code that I used.
Set<Id> idSet = new Set<Id>();
Map<Id, TestChild__c> children = new Map<Id, TestChild__c>([SELECT Id, Name FROM TestChild__c]);
public void methodOne(){
idSet = children.keySet();
for(Id childId : idset){
TestChild__c child = new TestChild__c();
child = children.get(childId);
child.Name = 'TestOne';
System.debug('Child Name : '+children.get(childId).Name); //result : TestOne
}
}