+ Start a Discussion

sobject clone agrument opt_preserve_readonly_timestamps

The sobject method clone recently received a new parameter for preserving read-only system fields like CreatedDate and LastModifiedDate. While this new argument appears to work for the cloned object immediately after the clone call itself, the values are overwritten during that new object's insertion. For example, suppose I want to clone a case to make an exact copy down to even the system fields using the following:

Case OldCase = [select Id, CreatedDate, ... from case];
Case ClonedCase = OldCase.clone(false,true,true);
Insert ClonedCase;

ClonedCase will have the current timestamp as its CreatedDate after the insertion, instead of the value from OldCase. I assumed there would be some magic involved during the insert to detect that the system fields were already set and to not overwrite them, but that's not the case. Am I misunderstanding the purpose of the preserve_readonly_timestamps argument?