CRM Deletion Service in CRM 4.0 and CRM 2011
Deletion service under CRM 4.0
All deleted records or entities under CRM 4.0 will not be directly deleted. Instead CRM will mark the objects in first step as “marked for deletion”. As a result, the marked objects could no longer be accessed by the web application or through SDK web service calls. This is called as “soft delete” and will be implemented by changing the objects attribute DeletionStateCode to status 2.
Possible status codes for the DeletionStateCode attribute:
If the DeletionStateCode of an object is set to 2, the object will be filtered out from all standard data views in the web application and is also not accessible through access via SDK web service calls.
The Deletion Service is responsible for the final removal of these marked objects from the database. Under CRM 3.0 these physical delete operation were handled by a windows service called Microsoft CRM Deletion Service.
Since CRM 4.0 the deletion operations will be scheduled as asynchronous operation, handled by the Microsoft CRM Asynchronous Processing Service. All activities of the Deletion Service are based on table named ScaleGroupOrganizationMaintenanceJobs, which can be found in the MSCRM_CONFIG database.
You can use the following sample script to delete all records marked for deletion immediately. As direct database manipulation is not supported, this should be done only in test and not in productive environment.
USE MSCRM_CONFIG
UPDATE dbo.ScaleGroupOrganizationMaintenanceJobs
SET NextRunTime = getdate()
WHERE OperationType = 14
Possible values for the OperationType attribute can be found here:
https://msdn.microsoft.com/en-us/library/bb887932.aspx
By default the SQL Server agent will trigger the job MSCRM_CONFIG.HardDelete every hour. This job will execute the stored procedure p_HardDelete, which will perform the deletion itself.
If the SQL Server Agent is not running, you have to wait on the Deletion Service itself. By default, the frequency of the Deletion Service job execution is set to once a day.
You can use the Scale Group Job Editor tool to change the execution frequency of the Deletion Service (Download here: https://code.msdn.microsoft.com/ScaleGroupJobEditor).
Deletion service under CRM 2011
With CRM 2011 the deletion of objects will change from “soft delete” to “hard delete”. We now no longer use Deletion State Codes for marking objects. Instead objects will be deleted immediately. This helps to improve performance and also reduces complexity in case of filtered views or tables.
Now the CRM 2011 Deletion Service will be used for removing system data and no longer user data. For example “Expired Outlook Client Subscriptions” or “Duplicate Detection Hash Codes for entities that no longer exists” are some of the system data, which will be removed by Deletion Service.
In case of migration from CRM 4.0 to CRM 2011, the upgrade process will hard delete any leftover marked for deletion records. You can cleanup these records to minimize downtime during migration.
A new version of the Scale Group Job Editor tool is currently under development and will be released on Codeplex, when the tool is available for download.
Greetings from the CRM team
Comments
Anonymous
April 01, 2012
This help me alot thanks it was an informative read. Helped me alot with my custom report.Anonymous
February 13, 2013
Nice