I have a requirement where I need to get the file names or count of files that are uploaded under each account in Salesforce. I understood that the notes and attachments can be queried from content version object but there isn't any field that displays the account name or id.

I also understood that from file detail view, we can see the account name which the file was shared with but it cannot be queried.

Is there any way that we can get the account id or account name from files or content version object. Please suggest.


I found the solution. Below is the soql to get the Files and Notes related to Account/any other object.

SELECT  contentdocumentid, Linkedentity.name,SystemModstamp, ContentDocument.title FROM ContentDocumentLink where Linkedentityid IN (SELECT Id FROM account)

To get the download links of your files or Notes, you need to take the contentdocumentid from above queried result and use them in below query

SELECT id, contentdocumentid FROM ContentVersion where contentdocumentid IN (<contentdocuementids from 1st query>)

Use Vlookup to match ids from second result sheet to first result sheet. replace the id in the following link to download the attachment: https://<you org domain>/sfc/servlet.shepherd/version/download/<id>?operationContext=S1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.