Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

How to delete records from the Attachment entity via SDK?

(0) ShareShare
ReportReport
Posted on by 5

I'm a C# developer and have been tasked with purging records from the Attachment entity for a GDPR requirement.

However when I invoke the 'Delete' method on the Xrm Sdk toolkit (Microsoft.Xrm.Sdk.IOrganizationService.Delete) the following exception is raised - "The 'Delete' method does not support entities of type 'attachment'." - ErrorCode: 0x80040800.

The Delete method works fine against the ActivityMimeAttachment entity and a number of other entities so question is how are you meant to delete Attachment entity records?

Apologies if I'm posting in the wrong place but I couldn't see a developer forum on the list...

  • Edwin71 Profile Picture
    5 on at
    RE: How to delete records from the Attachment entity via SDK?

    Thanks Erhan and David,

    I've tested this and deleting from the ActivityMimeAttachment entity does indeed delete from the Attachment entity.

    Worth noting that ActivityMimeAttachmentId and AttachmentId are two different Guids! So you need to make a note of the AttachmentId before deleting the ActivityMimeAttachment record or you won't be able to do a check...

  • erhan.keskin Profile Picture
    2,253 on at
    RE: How to delete records from the Attachment entity via SDK?

    Yes, do it. Just make document related fields Null, "IsDocument" field included.

    However, after doing it check in the "Attachment" table if the attachment is deleted from the table.

    docs.microsoft.com/.../annotation

  • David Jennaway Profile Picture
    14,065 on at
    RE: How to delete records from the Attachment entity via SDK?

    In addition to 'Filename' and 'MimeType' fields, setting 'FileSize' to zero and 'IsDocument' to No, you should also set the documentbody to null (this field stores the file contents)

  • Edwin71 Profile Picture
    5 on at
    RE: How to delete records from the Attachment entity via SDK?

    Thanks Erhan,

    Figured that was probably the case.

    Any thoughts on removing attachments from Notes whilst retaining the Notes record?

    We were thinking of blanking the 'Filename' and 'MimeType' fields, setting 'FileSize' to zero and 'IsDocument' to No.

    Regards,

  • Verified answer
    erhan.keskin Profile Picture
    2,253 on at
    RE: How to delete records from the Attachment entity via SDK?

    Hi,

    I assume you are either/both talking about purging annotation (Notes) and activitymimeattachment (Attachments) entities. Attachment is not an entity, it is a table in the database. So, activitymimeattachment and attachment tables work together to store the Attachments.

    If you need to delete Attachments, then pass the activitymimeattachment entity to the Delete method.

    If you need to delete Notes, then pass the annotation entity to the Delete method.

    Regards,

  • Edwin71 Profile Picture
    5 on at
    RE: How to delete records from the Attachment entity via SDK?

    Hi Rita,

    Thanks for the reply. So I guess my next question is how are we meant to conform to GDPR legislation if we can't delete from the Attachment entity? We have a legal requirement to delete customer data after a certain period of time.

    Is it possible that data in this entity is deleted as part of a cascading delete? I notice there is a relationship between Attachment and ActivityMimeAttachment ie:

    docs.microsoft.com/.../attachment

    Does deleting from ActivityMimeAttachment cause a delete to Attachment?

    Thanks.

  • Suggested answer
    Gilmeyer Profile Picture
    on at
    RE: How to delete records from the Attachment entity via SDK?

    Hi ,

    Im afraid Attachment entity does not support Delete request as it is not listed in the supported entities docs.microsoft.com/.../microsoft.xrm.sdk.messages.deleterequest.

    As an alternative you have the options listed in here docs.microsoft.com/.../microsoft.xrm.sdk.messages.deleterequest

    Thanks

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: How to delete records from the Attachment entity via SDK?

    Hello,

    Try "annotation".

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Adis Profile Picture

Adis 136 Super User 2025 Season 1

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 81

#3
Jonas "Jones" Melgaard Profile Picture

Jonas "Jones" Melgaard 77 Super User 2025 Season 1

Product updates

Dynamics 365 release plans