Deleting Teams in Dynamics CRM 4.0

Like many people I thought that teams could not be deleted so I was surprised to discover that teams can be deleted programmatically.

The SDK documents a TargetDeleteTeam class. So, teams can be deleted using the web services.

You'll need to know the GUID of the team record. Here is sample code:

  // Set up the CRM Service.
  CrmAuthenticationToken token = new CrmAuthenticationToken();
  token.AuthenticationType = 0;
  token.OrganizationName = "AdventureWorksCycle";

  CrmService service = new CrmService();
  service.Url = "http://crm/mscrmservices/2007/crmservice.asmx";
  service.CrmAuthenticationTokenValue = token;
  service.Credentials = System.Net.CredentialCache.DefaultCredentials;

  // Create the target object for the request.
  TargetDeleteTeam target = new TargetDeleteTeam();
  // EntityId is the GUID of the record being deleted.
  target.EntityId = new Guid("60F77BF5-6764-DF11-81DD-0003FF7E73B4");

  // Create the request object.
  DeleteRequest delete = new DeleteRequest();
  delete.Target = target;

  // Execute the request.
  DeleteResponse deleted = (DeleteResponse)service.Execute(delete);