• #15970
    Salesforce | Tanu Tanu #238
    Forcetalks

    What is the difference between Clone() and DeepClone() in Salesforce Apex?

    Hii All,

    I want to know the difference between between Clone() and DeepClone() in Apex.When should we use what? Can someone explain with an example?

     

    #15990
    Salesforce | vishnu vishnu #253
    Forcetalks

    Hi tanu,

    If a list is cloned, it duplicates it and has reference.
    If a list is DeepCloned, it duplicates and doesn’t have any reference.

    #24258
    Salesforce | PRANAV PRANAV #954
    Forcetalks

    Hi Tanu,

    CLONE

    • Creates a copy of the sObject record and keep the reference.
    • Supports primitive data type.
    • Parameters are not applicable.

    DEEPCLONE

    • 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.

    #27073
    Salesforce | Adarsh Adarsh #958
    Forcetalks

    Hi,

    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.

    #27096
    Salesforce | Archit Archit #957
    Forcetalks

    Clone : means creating a new record with the existing details of another reord.

    Here is the example:

    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.

Viewing 5 posts - 1 through 5 (of 5 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2020 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?