[SalesForce] Querying attachments in apex class

We have a custom object.
In the notes and attachments related list of this custom object we have uploaded few pdf and ms-word files (each of them of size < 5 mb)
we are not able to access the attachments by soql query inside apex class.

Further even in workbench a simple query 'SELECT Id, Name FROM Attachment' returns 0 records.

Best Answer

In Spring'16 release Salesforce introduced Files uploaded to the Attachments related list on records are uploaded as Salesforce Files, not as attachments in Salesforce Files Settings:

Files that you upload to the Notes & Attachments related list on records in Salesforce Classic are now Salesforce Files objects, rather than the old attachment objects. A new org pref in Salesforce Files Settings controls this behavior, and is enabled by default for new orgs.

The following SOQL query would allow you to get Ids of Files (Attachments) and New Notes related to the record SELECT ContentDocumentId,Id,LinkedEntityId,ShareType FROM ContentDocumentLink WHERE LinkedEntityId = 'YourRecordId'

Related Topic