I often get asked about quick ways to purge CRM data. Going directly to the database far to risky when it comes to deletion: since CRM supports an array of advanced deletion cascade rules which you might miss.

Here is a little script I wrote to purge some records from one of my CRM installations. Firstly I do a normal retrieve (see the standard SDK sample). Then using the RetrieveMultipleResponse result (retrieved) I just loop through it and execute the delete method of the service.

foreach (contact contact in retrieved.BusinessEntityCollection.BusinessEntities)

{

service.Delete("contact", contact.contactid.Value);

Console.WriteLine(contact.contactid.Value.ToString());

}

This posting is provided "AS IS" with no warranties, and confers no rights.

Tags: