• manjeera
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    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 ..