In Apex, what happens when you assign one sObject variable to another and modify it? Why?
#Apex
5 respuestas
When one sObject variable is assigned to another, both variables refer to the
same sObject instance
in memory.
For example:
Account acc1 = new Account(Name = 'Original');Account acc2 = acc1;acc2.Name = 'Updated';System.debug(acc1.Name); // Updated
Here, changing acc2.Name also changes acc1.Name because both variables reference the same Account object.
So, assigning an sObject variable does not create a new copy
of the record; it creates another reference to the same object.
Hope This Helps!!