# Write a SOQL query to fetch all files (ContentDocument / ContentVersion) linked to a specific Account record via ContentDocumentLink.

**Topic:** Development · **Difficulty:** Medium · **Asked at:** Deloitte, Accenture, Persistent · **Tags:** soql, scenario, files, content-document

Read it on the site: https://www.forcechallenges.com/interview-questions/write-a-soql-query-to-fetch-all-files-contentdocument-contentversion-linked-to-a-specific-account-record-via

## Answer

Files connect to records through `ContentDocumentLink` (`LinkedEntityId` is the record Id). Query the link and traverse to the ContentDocument for the file details.

```soql
SELECT ContentDocumentId, ContentDocument.Title, ContentDocument.FileExtension, ContentDocument.LatestPublishedVersionId
FROM ContentDocumentLink
WHERE LinkedEntityId = :accountId
```
To get the file body, query `ContentVersion` where `ContentDocumentId` matches and `IsLatest = true`.

---
Source: ForceChallenges · last updated 2026-10-19
