Mediachase.Commerce.Customers.CustomerContact cc = customerContext.GetContactById(YourGuid);
Mediachase.BusinessFoundation.Data.Business.BusinessManager.Delete(cc);
will delete the contact but if Contact have some orders then before that you have to delete all the orders first.
Could you try to set PreferredBillingAddressId and PreferredShippingAddressId to null before deleting it.
ContactEntity contact = (ContactEntity)BusinessManager.Load("Contact", customerContact.PrimaryKeyId);
if (contact != null)
{
contact.PreferredBillingAddressId = null;
contact.PreferredShippingAddressId = null;
BusinessManager.Update(contact);
}
BusinessManager.Delete("Contact", customerContact.PrimaryKeyId);
I might be late to the party but you can call this to delete contact and all belonged objects:
DeleteEntityWithDependsRequest request = new DeleteEntityWithDependsRequest(this.MetaClassName, custId, eRelatedEntityDeleteMode.Delete);
BusinessManager.Execute(request);
Regards.
/Q
Had the same problem and after reading this thread I ended up with this code that worked:
var contact = (ContactEntity)BusinessManager.Load("Contact", (PrimaryKeyId)currentContact.PrimaryKeyId);
if (contact != null)
{
contact.PreferredBillingAddressId = null;
contact.PreferredShippingAddressId = null;
BusinessManager.Update(contact);
}
var request = new DeleteEntityWithDependsRequest("Contact", (PrimaryKeyId)currentContact.PrimaryKeyId, eRelatedEntityDeleteMode.Delete);
BusinessManager.Execute(request);
Hello there,
I need to delete CustomerContacts from my EpiServer Commerce 7.5. I have the following code to do that:
However, when going through the BusinessManager.Delete function, an exception is raised with an InnerException regarding of foreign key constraints in the Database (quite normal considering contacts may have associated purchases, addresses, shipments and a quite long chain of dependencies I guess).
Has someone ever deleted a CustomerContact programatically? If so, how to do it cleanly and smoothly?
Thank you and kind regards