0

I have tried a few different methods to query for the Attachments in my org, but zero rows are always returned.

I ran this query in the query editor in dev console, but zero rows were returned:

select id, name from Attachment

The same result occurred when I ran below code in the execute anonymous window:

for (Attachment [] atts : [select name from attachment]) {
// do something with atts
system.debug ( atts.size() );
}

I'm expecting at least two rows to be returned on a Opportunity record that I'm using for testing. Is there something on the configuration end that I need to set up so that I'll be able to retrieve the attachments via soql? I'm guessing that there's something simple that needs to be tweaked that I overlooked.

1 Answer 1

2

If you're working on a newer org, the attachments are likely uploaded as Files, which can be accessed from the ContentVersion system object:

SELECT Id, Title, VersionData FROM ContentVersion

https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/api/sforce_api_objects_contentversion.htm

2
  • Just remember to add a query filter for the IsLatest if you want to get the latest version of the attachment, as a File (ContentDocument) can have multiple versions uploaded
    – Instread
    Commented Aug 17, 2020 at 19:52
  • Thanks! Your answer did the trick. Commented Aug 17, 2020 at 19:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .