+ Start a Discussion
sfdcrajsfdcraj 

clear old data from analytic snapshot after it runs and loads custom object with new data

Hi,

I have created an analytic snapshot which has source report (opportunity data) and loads it into custom object. I scheduled it to run daily. Now, when it runs it just inserts data into my custom object. It is not clearing the old data existing in the custom object. 

Is there any way I can clear out the old data, so that I have only the fresh copy of data every time ???


Regards,
raj.
SlashApex (Luis Luciani)SlashApex (Luis Luciani)
Hi Raj,

This functionality is not available out of the box, but you can achieve it with a trigger.

The trigger would activate after insert and would delete any records in the object that were not created on that day. Here is some code that might help. Keep in mind that this will only work if you are running the snapshot daily.
 
trigger deleteOldSnapshots on Snapshot__c  (after insert) {
	delete [SELECT id FROM Snapshot__c  WHERE CreatedDate < TODAY];
}

Hope this helps!
 
sfdcrajsfdcraj
Thanks Luis!!... but the snapshot failed and the error is 'Cannot put insert trigger on target object'.