/// <summary> /// Deletes are records from the cache and deletes them in CRM /// </summary> /// <param name="service"></param> public void DeleteAllCachedRecords(CrmService service) { Logger.WriteLine("Clearing cache"); foreach (var record in _aliasedRecords) { if (_aliasesToIgnore.Contains(record.Key) || _entitiesToIgnore.Contains(record.Value.LogicalName)) { continue; } try { Logger.WriteLine($"Deleting {record.Key}. ID: {record.Value.Id} Entity: {record.Value.LogicalName}"); service.Delete(record.Value); } // Some records can't be deleted due to cascading behavior catch (Exception ex) { Logger.WriteLine($"Delete failed: Error: {ex.Message}"); } } _aliasedRecords.Clear(); }