function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Christos KolonisChristos Kolonis 

How to get Attachments related to Opportunity

Hello, 

I am trying to get the Attachments related to Opportunity but in my query no attachments are found. I used the above code:
 
opportunity opp = [select id, name from opportunity];

list<Attachment> attList = [select id, name from Attachment where ParentId = :opp.id];

This query doesn't return any records. However the Attachments exist in this related list.

User-added imageAny ideas of how to get those attachments?

Thank you.
Best Answer chosen by Christos Kolonis
Christos KolonisChristos Kolonis
Found the solution so in case someone faces the same issue here is the answer:

For objects such as Account - Contacts, Opportunities, Contracts, Tasks, etc, in lightining experience attachments are not available, only files. So, as you can see when you try to upload a file, only "Upload File" is available and not "Attach File". The last option is only available to Salesforce Classic.
So, in order to get those records you have to query like this:
SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = '<Opportunity or other object id here>'