• #21086
     saloni gupta #648
    Forcetalks

    What are the parameters of a clone method in Salesforce?

    What are the parameters of a clone method, sometimes we call clone method by one parameter , sometimes by two and more. how would we differentiate when to use one/two/three/four parameters?

     

    #21148
    Salesforce | Sudhir Sudhir #576
    Forcetalks

    I am not going to duplicate the explanation if it is already existing somewhere.

    Bringing it at your click here:   Clone Explained

    Let me know if you wanted to know any specifics which are not explained in this blog post.

    #24488
    Salesforce | PRANAV PRANAV #659
    Forcetalks

    Hi Saloni,

    clone(opt_preserve_id, opt_IsDeepClone, opt_preserve_readonly_timestamps, opt_preserve_autonumber)

    opt_preserve_id
    Type: Boolean
    Determines whether the ID of the original object is preserved or cleared in the duplicate. If set to true, the ID is copied to the duplicate. The default is false, that is, the ID is cleared.

    opt_IsDeepClone
    Type: Boolean
    Determines whether the method creates a full copy of the sObject field, or just a reference:
    If set to true, the method creates a full copy of the sObject. All fields on the sObject are duplicated in memory, including relationship fields. Consequently, if you make changes to a field on the cloned sObject, the original sObject is not affected.
    If set to false, the method performs a shallow copy of the sObject fields. All copied relationship fields reference the original sObjects. Consequently, if you make changes to a relationship field on the cloned sObject, the corresponding field on the original sObject is also affected, and vice-versa. The default is false.

    opt_preserve_readonly_timestamps
    Type: Boolean
    Determines whether the read-only timestamp fields are preserved or cleared in the duplicate. If set to true, the read-only fields CreatedById, CreatedDate, LastModifiedById, and LastModifiedDate are copied to the duplicate. The default is false, that is, the values are cleared.

    opt_preserve_autonumber
    Type: Boolean
    Determines whether auto number fields of the original object are preserved or cleared in the duplicate. If set to true, auto number fields are copied to the cloned object. The default is false, that is, auto number fields are cleared.

    Note: All the parameters are optional.

    Sample Code:

    Phase__c phaseObj = [SELECT Name, Milestone__c FROM Phase__c LIMIT 1];

    Phase__c phaseCopy = phaseObj.clone(false, false, false, false);

    If you insert phaseCopy, it will be the exact copy of phaseObj.

    Hope this helps you.

Viewing 3 posts - 1 through 3 (of 3 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 2018 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?