Search code examples
c#dynamics-crmmicrosoft-dynamicsxrm

Delete using alternate key


Since we can update an entity using an alternate key:

var entity = new Entity("my_entity", "my_alternate_key", "my_value");
entity["my_updated_field"] = "Update";
service.Update(entity);

I was expecting to be able to delete the same kind of way:

var ref = new EntityReference("my_entity", "my_alternate_key", "my_value");
service.Delete(ref);

But Delete can only take a Guid

Is there a way to delete a record using a an alternate key ?

I mean without retrieving it before


Solution

  • You cannot delete by alternate key using the Organization Service. For that you need to have the guid of the record in question (e.g. by retrieving it first).

    It is possible to delete using alternate keys via the Web API as shown on MSDN:

    Any time you need to uniquely identify an entity to retrieve, update, or delete, you can use alternate keys configured for the entity