Clone
|
DeepClone
|
If a list is cloned, it duplicates it and has reference.
|
If a list is DeepCloned, it duplicates and doesn’t have any reference.
|
Primitive data types are supported.
|
Primitive data types are not supported.
|
Parameters:
Not applicable
|
Parameters:
Boolean opt_preserve_id – Whether cloned sObjects records ids are maintained.
Boolean opt_preserve_readonly_timestamps– Whether cloned sObjects records read only system fields like createdDate, LastModifiedDtate, etc are maintained.
Boolean opt_preserve_autonumbe– Whether cloned sObjects records auto number fields are maintained.
|
Sample Code:
Account Account1= new Account(Name='Test1');
Account Account2= new Account(Name='Test2');
List<Account> AccountList = new List<Account>{Account1, Account2};
List<Account> listDuplicate = new List<Account>();
listDuplicate = AccountList.clone();
AccountList.get(0).Name = 'Testing1';
system.debug(AccountList.get(0).Name + ',' + listDuplicate.get(0).Name);
Now AccountList.get(0).Name and listDuplicate get(0).Name will be ‘Testing1’.
listDuplicate.get(0).Name = 'Testing2';
system.debug(AccountList.get(0).Name + ',' + listDuplicate.get(0).Name);
Now AccountList.get(0).Name and listDuplicate get(0).Name will be ‘Testing2’.
|
Sample Code:
Account Account1= new Account(Name='Test1');
Account Account2= new Account(Name='Test2');
List<Account> AccountList = new List<Account>{Account1, Account2};
List<Account> listDuplicate = new List<Account>();
listDuplicate = AccountList.deepClone();
AccountList.get(0).Name = 'Testing1';
system.debug(AccountList.get(0).Name + ',' + listDuplicate.get(0).Name);
Now AccountList.get(0).Name will be ‘Testing1’ and listDuplicate get(0).Name will be ‘Test1’.
listDuplicate.get(0).Name = 'Testing2';
system.debug(AccountList.get(0).Name + ',' + listDuplicate.get(0).Name);
Now AccountList.get(0).Name will be ‘Testing1’ and listDuplicate get(0).Name will be ‘Testing2’.
|
Aptitude
(12)
C
(2)
C++
(10)
CSS
(1)
Data Structure
(2)
English
(6)
Fitness
(2)
General
(14)
HTML
(3)
Integration
(1)
Itinerary and Travel Cost
(2)
Java
(29)
JQ
(5)
JS
(5)
JSP
(1)
Lightning
(14)
logical
(3)
Lyrics
(1)
Math
(1)
Music Notation
(20)
MySql
(4)
Network
(1)
Regex
(1)
salesforce
(131)
Servlet
(4)
SF Admin
(31)
SF Dev
(102)
Spiritual Content
(3)
SQL
(4)
SQL_SERVER
(1)
StudyPoints
(2)
Trips
(1)
ytChannels
(2)
अन्ताक्षरी
(4)
Cloning
Subscribe to:
Posts (Atom)