I am using CRM version 9.0 and I want to delete all records with same ID in CRM through C#.
I want to achieve something like this (I am giving a SQL Query example just for reference purpose)
Delete from entityName where id = @id
Currently, I am creating records in CRM through my C# code using below
dictionary.Add("code", new CrmDataTypeWrapper(code, CrmFieldType.Raw));
dictionary.Add("id", new CrmDataTypeWrapper(id, CrmFieldType.Raw));
Guid EvntId = _client.CrmInterface.CreateNewRecord("entityname", dictionary, "", false, new System.Guid());
Now I want to write a code block before this logic which will delete all the records if they exist of the passed ID.
If you are not sure whether or not those ids exist in Dynamics, you should try-catch your Delete attempt, because if you try to delete a record that does not exist in Dynamics, Dynamics will throw you a
FaultException
.