- September 13, 2016 at 1:42 pm #15970Tanu #238
What is the difference between Clone() and DeepClone() in Salesforce Apex?
I want to know the difference between between Clone() and DeepClone() in Apex.When should we use what? Can someone explain with an example?September 14, 2016 at 7:46 am #15990vishnu #253
If a list is cloned, it duplicates it and has reference.
If a list is DeepCloned, it duplicates and doesn’t have any reference.January 19, 2018 at 1:14 pm #24258PRANAV #954
- Creates a copy of the sObject record and keep the reference.
- Supports primitive data type.
- Parameters are not applicable.
- Generally it clone the list of object but don’t hold any reference.
- It doesn’t support primitive datatype.
- Parameter are applicable.
Hope this helps you.March 30, 2018 at 10:14 am #27073Adarsh #958
Clone(): When you clone an sObject in Apex, it copies all the fields populated in that Apex object, not necessarily all fields on the record. … If you do the following, the clone will not have LeadSource and Status cloned from the original record. It will use the default values for Leads.
DEEPCLONE(): If a list is DeepCloned, it duplicates and doesn’t have any reference.
Parameters of DEEPCLONE:
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.March 30, 2018 at 10:39 am #27096Archit #957
Clone : means creating a new record with the existing details of another reord.
Here is the example:123Account acc = [SELECT Name, Type FROM Account LIMIT 1];Account accCopy = acc.clone(false, false, false, false);
if you insert accCopy, it will be the exact copy of acc.
DeepClone : creating a new record with the existing details of another record along with related lists.
Please Register to reply to this topic. /