+ Start a Discussion
TechMightyTechMighty 

Autonumber field value not preserved when inserting cloned record

Hi,

 

Can anybody please help to understand "Boolean opt_preserve_autonumber" parameter of clone method?

 

I am trying to create a cloned object of account object but there is an autonumber field "Account Number". When I set this parameter value to true i could see that the cloned object hold the same old value but when I try to inser the same cloned record the value changes automatically to next autonumber value.

 

can this be avoided?

 

Regards,

Suyog

 

souvik9086souvik9086

After cloning why are you still trying to insert that data?

If you insert it separately it will invoke new autonumber value automatically.

 

Thanks

TechMightyTechMighty

Hi,

 

If we dont need to insert cloned record explicitly, then how can i ensure that the object instance is saved in the salesforce?

 

I mean how can i ensure that the cloned record is stored properly?

 

Regards,

Suyog

VaasuVaasu
You can confirm whether your cloned record got saved or not by using "Database.SaveResult[]" class.

Please refer below
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_database_saveresult.htm
TechMightyTechMighty

Hi,

 

I went through the link, but i can see that Database.SaveResult[] class is the outcome of either insert or update method call.

 

When we clone an object using this statement "Account__c acc_clone = accobj.clone(false,true,true,true);" how can i save cloned object (acc_clone)?

I want to save all the changes to made to clone object and am using custome page for navigations.