You need to sign in to do that
Don't have an account?

Does salesforce supports cloning of Sobject using Clone method
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 ..
So, you're thinking of the "reference" type as being a true "same memory location" reference for *the SOBJECT* being cloned. (e.g. what you'd see if you tested using "===" instead of "==".)
However, when you clone you *always* get a new SObject. The deep vs. shallow question doesn't refer to the SObject itself, it refers to data structures inside the Sobject that refer to other sobjects.
For example:
Best, Steve.
All Answers
So, you're thinking of the "reference" type as being a true "same memory location" reference for *the SOBJECT* being cloned. (e.g. what you'd see if you tested using "===" instead of "==".)
However, when you clone you *always* get a new SObject. The deep vs. shallow question doesn't refer to the SObject itself, it refers to data structures inside the Sobject that refer to other sobjects.
For example:
Best, Steve.
I REALLY APPRICIATE YOUR HELP...
Through Code we are creating copy of sobject. After creation of copy , where to find that clone object? I am not able to find that clone object in custom objects list.
Please let me know
Thanks,
manju
Hi,
I was just having same question when i got to see your post. I have a doubt on this ... can you plz help me clarify?
Account a = new Account (Name = 'San Clone');
insert a;
Contact c = new Contact (Lastname = 'Chatterjee', AccountId=a.Id);
insert c;
Contact cdeep = c.clone(false, true);
Contact cshallow = c.clone(false, false);
insert cdeep; insert cshallow;
When I go into system and see the Ids of c, cdeep, cshallow and their accounts, I have 3 diff. ids for c, cdeep and cshallow, but all referring to one single Account! so i still fail to understand what is the difference between using deep clone and shallow clone...
Although this is an old post and already answered, I would like to mention about "iClone" app. It may help someone looking for similar needs, but do not have developer skills or the time to develop.
Here is the link https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000B39tWEAR
You can clone any object with any related list. You can choose which fields to clone and provide default values as well.
Programatically, sobject.clone() clones objects, however, taking it to Salesforce jargon, it is actually clonning records.
Something weird I saw happening with the deep clone , that actually makes sense, is that the collection of clonned children object still point to the original master.
In this example I iterate through the clone children just to re assign them to the new Parent :