function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bps2009bps2009 

Code to clone records every week?

Hi all,

 

I currently have a custom object that is related to accounts, and we use it for logging information in on the same day every week. Sometimes the information is just the same as the previous week.

 

Does anyone know if there is some apex code I could use that would automatically clone  the previous weeks record on the same day every week? So say on a Monday, all records created in the custom object last week would get cloned?

 

Many thanks for your help,

BPS

Best Answer chosen by Admin (Salesforce Developers) 
PragadheeshwariPragadheeshwari
Analytic Snapshot is better to do,combination of time dependent workflow and trigger will be a tough process.

All Answers

sfdcfoxsfdcfox
You could use the Analytic Snapshot feature to have the system automatically run a report and copy data from your custom object to another for archival purposes. Alternatively, you can use the new Batchable interface to set up some Apex Code that runs periodically, creating new records that contain the data you would like to capture.
indranily81indranily81

A combination of time dependant workflow and trigger can solve the problem. 

 

 

Thanks

indranily81

PragadheeshwariPragadheeshwari
Analytic Snapshot is better to do,combination of time dependent workflow and trigger will be a tough process.
This was selected as the best answer
bps2009bps2009

Thanks for the suggestions everyone - i have set this up using the analytical snapshots as suggested and it seems to work well with it configured to run at 1am every Monday in time for the working day.

 

The only limitation I had was that it wouldnt allow me to map Long Text Area's (32,000), so I've had to change these to 255 text areas.