Loading

Why SOQL Queries Return Fewer Files Than the Storage Usage Page

Data pubblicazione: May 27, 2026
Descrizione

Issue

Salesforce administrators may observe significant discrepancies between the number of ContentDocument records returned by SOQL queries and the ContentBody record count displayed on the Storage Usage page. This leads to confusion about actual file storage consumption and difficulty managing storage quotas.
For example, an administrator may run SELECT COUNT() FROM ContentDocument and receive 50,000 records, while the Storage Usage page shows 80,000 ContentBody records. This difference is expected — the additional records originate from platform features like ContentNote records, embedded images in Rich Text fields (ContentReference), and Chatter feed posts with attachments that are not accessible via standard ContentDocument SOQL.

Symptoms

  1. SOQL queries on ContentDocument or ContentVersion return significantly fewer records than expected.
  2. The Storage Usage page displays a much higher ContentBody count.
  3. The sum of individual user storage in "Top Users by File Storage Usage" does not match the total file storage usage.
  4. Administrators cannot locate or access all files contributing to storage consumption through standard SOQL queries.

Cause

This behavior is working as designed. The Storage Usage page uses algorithms that account for all ContentBody usage across multiple platform features — not just ContentVersion records. ContentBody storage includes data from the following sources:

  • ContentVersion records (standard file uploads)
  • ContentReference records (images and files embedded in Rich Text fields)
  • ContentNote records (which internally use Rich Text fields)
  • Feed posts with embedded images and rich content
  • Other platform features that utilize blob storage

SOQL Query Limitations:

  • SOQL queries on ContentDocument and ContentVersion only return files directly accessible to the querying user.
  • Simple COUNT() queries cannot replicate the complex storage calculations used by the platform.
  • SOQL queries do not account for all sources of ContentBody usage across the platform.
Risoluzione

The discrepancy between SOQL results and Storage Usage calculations is expected behavior. The Storage Usage page provides the authoritative view of actual storage consumption across all platform features, while SOQL queries show only a subset of accessible files.

Recommended Approaches for Storage Management

1. Use Storage Usage Page as Primary Reference

  • Rely on the Storage Usage page for accurate storage consumption metrics.
  • Use the "Top Users by File Storage Usage" section to identify high-usage users.
  • Use the detailed user storage breakdown to prioritize cleanup efforts.

2. Enable Proper File Access Permissions

  • Ensure administrators have the "Query All Files" permission enabled.
  • Remove "Query Non Vetoed Files" permission from human user profiles (this permission is intended for system integrations only).
  • Verify that administrators can access files across all libraries and sharing boundaries.

3. Comprehensive File Cleanup Strategy

  • Target high-usage users identified in the Storage Usage page.
  • Clean up Rich Text field content that may contain embedded images.
  • Review and clean up Chatter feed posts with attachments.
  • Use "Login As" functionality to access individual user files when necessary.
  • Focus on ContentNote cleanup if extensive note-taking features are used.

4. Alternative Query Approaches

  • Query by CreatedById or OwnerId to find files created or owned by specific users.
  • Access individual user storage details through links on the Storage Usage page.
Numero articolo Knowledge

005224377

 
Caricamento
Salesforce Help | Article