Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
Full Content Document entry
How-to guide

How to work with Content Document in Salesforce

Most users interact with Content Document through the Files UI rather than the object directly. For developers and admins, the object is queryable through SOQL and writable through Apex with a few gotchas around version handling.

By Dipojjal Chakrabarti · Founder & Editor, Salesforce DictionaryLast updated May 20, 2026

Most users interact with Content Document through the Files UI rather than the object directly. For developers and admins, the object is queryable through SOQL and writable through Apex with a few gotchas around version handling.

  1. Confirm Salesforce Files is enabled

    All editions above Group Edition have Salesforce Files enabled by default. If you only see the legacy Notes and Attachments related list, ensure the Files Related List is added to the page layout in Setup, Object Manager, Page Layouts.

  2. Upload a file from a record

    Open any record (Case, Account, Opportunity). In the Files related list, click Upload Files. Salesforce creates a Content Document, a Content Version with the binary, and a Content Document Link tying it to the current record.

  3. Attach an existing file to another record

    From a different record, click Add Files in the Files related list. Salesforce shows a picker of existing Content Documents you have access to. Selecting a file creates a new Content Document Link without duplicating the binary.

  4. Query Content Document programmatically

    SOQL like SELECT Id, Title, FileType, ContentSize, LatestPublishedVersionId FROM ContentDocument WHERE Id IN ... The LatestPublishedVersionId joins to the active Content Version. Most useful queries also join Content Document Link to find which records a file is attached to.

  5. Upload a new version through Apex

    Insert a new Content Version with the same ContentDocumentId as an existing Content Document. Salesforce automatically updates the LatestPublishedVersionId pointer on the parent.

  6. Delete a Content Document

    Deleting a Content Document cascades to delete all Content Versions and Content Document Links. Use delete carefully; this is destructive and reduces storage but removes the file from every record it was attached to.

Gotchas
  • Content Document is the parent; Content Version is the per-version child. Updating metadata on the wrong object is a common bug.
  • Removing all Content Document Links does not delete the Content Document. The file persists in storage until you delete the Content Document itself.
  • Apex code that inserts Content Version without an existing Content Document creates a new Content Document automatically. To version an existing document, set the ContentDocumentId on the new Content Version explicitly.
  • Attachment and Content Document are different objects with different APIs. Code targeting Attachment will not find files stored as Content Document and vice versa.
  • Files larger than 2 GB cannot be uploaded as a Content Document. For very large files, use Salesforce Files Connect with external storage.

See the full Content Document entry

Content Document includes the definition, worked example, deep dive, related terms, and a quiz.