In this blog post, we’ll break down what BulkDeleteRequest class does, how it works, and show you how to execute it via code example.
What is the BulkDeleteRequest Class?
The BulkDeleteRequest class is your trusty data operator within the Dynamics 365 environment. It’s the go-to tool for cleaning up your data in large batches. Whether you want to remove outdated records, clean up duplicates, or simply keep your database tidy, this class is your friend.
The BulkDeleteRequest class in Dynamics 365 offers several advantages over the standard DeleteRequest when it comes to managing large-scale data deletion operations.
The primary advantage of the BulkDeleteRequest class is efficiency. When you use DeleteRequest to delete records one by one, it can be time-consuming and resource-intensive, especially when dealing with a large number of records. In contrast, the BulkDeleteRequest class performs bulk operations, significantly reducing the time and resources required to complete the task.
BulkDeleteRequest is optimized for bulk deletion. It processes records in batches, which means it can handle large volumes of data more effectively without causing performance issues in the Dynamics 365 system. This is crucial for maintaining system responsiveness and ensuring that other operations can continue smoothly.
How BulkDeleteRequest Performs:
The BulkDeleteRequest class performs deletion operations in the following manner:
- Query Definition: You start by defining a FetchXML query that specifies the criteria for selecting the records you want to delete. This query can be as simple or as complex as needed to target the right set of records.
- Execution: After defining the query, you create and execute a
BulkDeleteRequestinstance, providing the FetchXML query as part of the request. Dynamics 365 processes this request asynchronously in the background. - Background Processing: The bulk delete operation is performed in the background by the Dynamics 365 system. The system processes records in batches, deleting them based on the criteria you defined in the query.
- Completion Notification: You can receive email notifications or monitor the progress of the bulk delete operation to know when it’s completed.
While the BulkDeleteRequest class is a powerful tool for managing data in Dynamics 365, there are certain scenarios where it may not be the best choice:
- Small-Scale Deletions: If you only need to delete a handful of records, using
DeleteRequestor manual deletion might be more straightforward and quicker.BulkDeleteRequestis designed for large-scale data operations. - Immediate Record Deletion: If you require records to be deleted immediately,
DeleteRequestcan be used for real-time deletion, whereasBulkDeleteRequestoperates asynchronously and may take some time to complete. - Complex Record Deletion Logic: If you need to execute complex business logic or perform custom actions during record deletion,
DeleteRequestmay be more suitable as it allows you to customize the deletion process on a per-record basis.
Code
This code snippet initiates a bulk delete job based on specified criteria. Once the job successfully completes, it triggers an email notification to the relevant user.
Monitoring BulkDeleteRequest Job
1) Select Settings, Data Management.
2) Click Bulk Record Deletion.
3) Change your view to Recurring Deletion System Jobs.
For more information about parameters you can visit the official MS Docs by clicking here.
Leave a comment