+ Start a Discussion
David81David81 

Class to run monthly to copy data from custom object 1 to new record in custom object 2

Hello all,

 

Beginner Apex developer here again. Nearly complete with a project and now I need to write a class that I can run monthly with new apex  scheduler.

 

All it needs to do is take data from records in a custom object (all records) and create new records in a second custom object with all that data.

 

Custom Object 1 = Updates of MTD live data from our phone system for each sales rep.

Custom Object 2 = Month end snapshots for historical tracking puposes.

 

I'm sure there is an easy way to do this, but with my limited knowledge I'm not sure where to start. If some kindly developer could point me in the right direction, I'm sure I can put the pieces together.

Best Answer chosen by Admin (Salesforce Developers) 
Always ThinkinAlways Thinkin

Hi David,

Have you considered using Analytic Snapshots for that? It's fairly effective if you're not grabbing more than 2000 records to snapshot. If you're managing more than 2000 sales reps, I pray for you.

All Answers

Always ThinkinAlways Thinkin

Hi David,

Have you considered using Analytic Snapshots for that? It's fairly effective if you're not grabbing more than 2000 records to snapshot. If you're managing more than 2000 sales reps, I pray for you.

This was selected as the best answer
David81David81

Hadn't looked into Analytic Snapshots, but will give it a go and post back if it won't work for what we need. We just started using Salesforce so I'm learning a lot very quickly. Currently our sales team is about 25 reps. I don't see it going any where near 2000 any time soon.

 

 

David81David81

Analytic Snapshots looks perfect! Thank you.

 

The only issue I can find it trying to set the owner of the new record. The source object has an owner and another lookup field to set the user that is being reported on. 

 

When I create a report to feed the snapshot though, I can't set anything to populate the Owner of the new record. I see "(No fields with compatible data type)".

 

And, of course, I can't use an insert trigger or workflow rule to set this either. 

 

Am I missing something painfully obvious here?

David81David81
Sorry. Got it. New Custom Report Type Created.
Always ThinkinAlways Thinkin
Great! Glad they work. I don't use them often but they definitely fill a need that would be a hassle to build otherwise! Keep an eye on storage, they can eat it up quickly.
David81David81
Storage shouldn't be too much of an issue. Each month will probably only cost us about 50k.
vinnu2012vinnu2012

Hi ,

 

I have the same requirement. Could you please send me the sample code for this requirement.

 

Thanks,

satya