Permanently Delete Datasets and Alignments
The DoCleanup() Apex method is the equivalent of clicking Permanently Delete in Territory Planning Data Management in Setup. You can permanently delete datasets only with a Deleted status as shown on the Territory Planning Data Sets page. When you permanently delete a dataset, all alignments created from that dataset’s source are also permanently removed.
Dataset and alignment cleanups can run at scheduled times or after a user deletes a dataset in the UI.
Signature
AsyncApexJob maps.TPSDK.DoCleanup()
- AsyncApexJob represents an individual Apex sharing recalculation job, a batch Apex job, a method with the future annotation, or a job that implements Queueable. Use this object to query Apex batch jobs in your organization.
- maps is the namespace that's available after you install Salesforce Maps.
- TPSDK is the class that contains the Salesforce Maps Territory Planning global methods exposed to developers.
- DoCleanup() is the method.
Sample Code
This code runs dataset and alignment cleanups at scheduled times. The DoCleanup() method returns an AsyncApexJob containing the number of items processed, the date and time of job completion, and other details.
Example
// Implement as Schedulable to run the Apex class at regular intervals.
public with sharing class TerritoryPlanningCleanupSchedule implements Schedulable {
// Invoke the scheduled Apex class with the execute() method.
public void execute(SchedulableContext SC) {
AsyncApexJob cleanupJob = maps.TPSDK.DoCleanup();
System.debug('Cleanup job is ' +cleanupJob.Status+ '. ' +cleanupJob.JobItemsProcessed+ ' of ' +cleanupJob.TotalJobItems+ ' batches processed.');
}
}