How to Clone a Record Programmatically and Set Audit Fields
Ever want to clone a record with full control over the resulting record?
I recently was testing a time-based Process Builder and found myself frustrated by the one-hour minimum on the PB. I didn't want to wait that long to verify if it was working correctly.
I could clone records for testing, but I couldn't force the Created Date, so I'd have to wait the full hour.
Here's a snippet I came up with that will do just that for you. In my case, I have it set so that the createddate of the record will be 55 minutes ago, making testing the PB with a one-hour window much easier.
You can run this in Execute Anonymous, and you only have to set the first two fields under "Setup." The other three are optional.
Feel free to reach out if you have any questions.