Create a scheduled job code to delete any FedEx checkpoints for shipments that have been delivered more than 2 week ago
Todays blog post will show you the code needed to set up a scheduled job that will remove all FedEx checkpoint objects for shipments that have been delivered more than 2 weeks ago.
This is useful if you are coming up against salesforce storage limits and need to clear out some space.
We will need to create two classes and then their respective test classes.
This class creates the list of all the checkpoints that need to be deleted.
Line 7 creates the SELECT query, and Line 15-16 is where the DELETE statement is executed.
This class is needed to execute the RemoveDeliveredCheckpointsBatch above, and will be the class that we use the Schedule Apex on your production instance, once these classes have been deployed.
The test class for RemoveDeliveredCheckpointsBatch
The test class for RemoveDeliveredCheckpointsScheduler
Next you need to create the changeset and deploy these classes into your production environment.
Once in your production environment you need to go to Setup > Develop > Apex Classes and click on the schedule Apex button:
Fill in the details and remember to input RemoveDeliveredCheckpointsScheduler into the Apex class field.
If you want the job to run everyday at 5am then set up the page like so:
Click Save, and you’re finished.
Please let us know if you have any questions and we will be happy to help.