[SalesForce] Creation order of ContentNote and ContentDocument

When you create a new enhanced Note in the UI, it creates a ContentNote and a ContentDocument record. Does anyone know the creation order of the records? Client wants me to write a trigger for the enhanced Note, and triggers are allowed only for ContentDocument, not ContentNote.

Best Answer

Disregard my ill-informed comment to your OP

ContentNote is saved with key prefix 069 which is a ContentDocument. And, ContentDocument is the parent of ContentVersion (key prefix of 068).

You can think of the ContentDocument as the header and ContentVersion as the actual "note" -- with multiple versions supported. As you edit the Note and click Save, a new ContentVersion is created - but under the same ContentDocument

Since ContentNotes are typically added as children to some Object (like Account or Opportunity), the relationship between the ContentNote (i.e. ContentDocument) and the Account or Opportunity is handled via a ContentDocumentLink.

So, what happens first when the Note is first saved?

  1. ContentVersion is created (trigger possible)
  2. ContentDocument is created (happens automatically when the first ContentVersion is saved). Trigger is also possible although it is not clear to me if you'll get control when this object is initially inserted via the side effect of #1
  3. ContentDocumentLink is inserted - the link(junction) between the Account (or Opportunity or ...) and ContentDocument - trigger also possible
Related Topic