• ashish_singh
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies

below is the code that i have tried to do the cloning.

 

Account acc=new  Account(Name='ACC');
insert acc;
Opportunity CloneOpp= new Opportunity(Name='CloneOpp',AccountId=acc.id,Amount=222,StageName='xyz',CloseDate=System.today(),h1newContractEndDate__c=System.today());
 insert CloneOpp;

 Opportunity colned=CloneOpp.clone(true,false);
      
        
  system.debug('*Id=*'+colned.id);
  system.debug('source id='+CloneOpp.id);
 system.debug('*name*'+colned.Name);
  system.debug('opp='+CloneOpp.Name);


     colned.Name='TestNew';

   system.debug('*name after update*'+colned.Name);
   system.debug('Source opp Name='+CloneOpp.Name);//this should be print TestNew but it prints CloneOpp

 

apex guide says-" If "opt_IsDeepClone" argument set to false, the method creates a reference to
the original sObject. Consequently, if you make changes to a field on the cloned sObject, the original
sObject is also affected".

 

 

please guide if any one has answer of this ..

Hi,

 

i want to know that ,what is the use of  the folowing  arguments of "clone" method opt_preserve_id and opt_IsDeepClone.

 

in developer guide it is mentioned that if we pass false for opt_IsDeepClone, than it's create the referance of SObject and what ever changes we will do in cloned object that  will refelect in to the source object.

but when i did this ,i din'nt seen this difference .

please guide.

below is the code that i have tried to do the cloning.

 

Account acc=new  Account(Name='ACC');
insert acc;
Opportunity CloneOpp= new Opportunity(Name='CloneOpp',AccountId=acc.id,Amount=222,StageName='xyz',CloseDate=System.today(),h1newContractEndDate__c=System.today());
 insert CloneOpp;

 Opportunity colned=CloneOpp.clone(true,false);
      
        
  system.debug('*Id=*'+colned.id);
  system.debug('source id='+CloneOpp.id);
 system.debug('*name*'+colned.Name);
  system.debug('opp='+CloneOpp.Name);


     colned.Name='TestNew';

   system.debug('*name after update*'+colned.Name);
   system.debug('Source opp Name='+CloneOpp.Name);//this should be print TestNew but it prints CloneOpp

 

apex guide says-" If "opt_IsDeepClone" argument set to false, the method creates a reference to
the original sObject. Consequently, if you make changes to a field on the cloned sObject, the original
sObject is also affected".

 

 

please guide if any one has answer of this ..