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
Oriel SupportOriel Support 

Need to export and delete very old tasks

I need to export tasks owned by an individual that are 2 years old or more and then delete them.  The client would like this to be a repeatable task scheduled monthly.  I have done a lot of research and found several articles about manual operations in data loader, and also with using the cli and windows task scheduler.  I have also looked at apex and I think this might be the way to go.  I am a relative newbie with apex, but I am a long time developer in many other platforms including java, html, sql, c#, and others.  I just need a push in the right direction to get started.  Any tips on the best method to accomplish this would be appreciated.
David GuzmanDavid Guzman
I would say try using the data export under data management to pull the required information. Form there, you would also be able to set up the automated monthly scheduling of exporting the data. Apex will be a great option to use and delete but there is also a mass delete feature in which if defined correctly can eliminate older files that are not needed anymore or are out dated after the data export of course.
Oriel SupportOriel Support
The client has a weekly export setup already.  The export I want is simply the records we are going to delete.  The mass delete feature has a limit of 250 records and we may have more than that in a month.  I would like to put this in a format that can either be setup as a manual one button click to purge the tasks or an autmated monthly process, even if I have to schedule it in windows on one of their workstations.
 
David GuzmanDavid Guzman
Are there any predefined notions on what is wanting to be kept and what is to be deleted? In example, Report names, folders,  or certain dates? I believe that the Mass Delete report can define those terms. But it makes sense that after 250 may be an issue for the first set due to being the first run. In relation to automation, have you checked any on the appexchange to see if there is anything out there yet made for it? You should also be able to set up automated reports through Salesforce. I must also let you know that I am still in progress of learning the in depth of Salesforce. Let me do some playing in the sandbox and maybe can help you get something going
Oriel SupportOriel Support
Final detailed requirement:

Need to remove any task owned by a particular user, does not contain the word "CLICKS" in the subject, and is 2 years old or more whether it has been archived or not.  There is no need to export it to a save file/report.  The user simply wants it permanently deleted.

I only see a mass delete option for Activities, not just the tasks.  We do not want to remove the Activity.  We also want to schedule this process monthly.
Oriel SupportOriel Support
Just bumping this question.  I am new to the APEX coding and would like some pointers on developing the process to delete old tasks.  I am not sure if I should create a class, trigger, or what.  I am an experienced developer and I just need some direction on the best method to do this in salesforce.
Michael TomarMichael Tomar

If you are looking for a way to do it automatically, you may try out Skyvia online data import tool. It also allows you to schedule these processes. Please find a tutorial here (https://skyvia.com/blog/how-to-mass-delete-records-from-salesforce-using-sql-or-data-loader).

They also have ready-made queries, this one (https://skyvia.com/gallery/salesforce-mass-delete-tasks) may be helpful in your case:
DELETE FROM Task