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
Mike Bucci 6Mike Bucci 6 

I am trying to execute a basic SOQL query to pull the ID of an attached file but it is not returning anything. Here is what I have: SELECT Id FROM Attachment WHERE ParentId = '5005000000qtXXXXX' Any suggestions?

Here is what I have:  SELECT Id FROM Attachment WHERE ParentId = '5005000000qtXXXXX'  

Any suggestions?
Best Answer chosen by Mike Bucci 6
Raj VakatiRaj Vakati
Use this query  .. You need to use ContentDocumentLink and not attachements 
 
SELECT ContentDocumentId,ContentDocument.Title, ContentDocument.CreatedDate,LinkedEntityId
FROM ContentDocumentLink where LinkedEntityId='5005000000qtXXXXX'  

 

All Answers

Raj VakatiRaj Vakati
is your parent id is correct ??

Are you using attachements or file s?


Do one thhink 


First Query without where condition and see 
Use this SOQL 

SELECT Id ,ParentId  FROM Attachment 

See the above Query you are getting the parentID which you are using in where the condition 

 
Mike Bucci 6Mike Bucci 6
Parent is correct.  I am using attached files.
Raj VakatiRaj Vakati
Use this query  .. You need to use ContentDocumentLink and not attachements 
 
SELECT ContentDocumentId,ContentDocument.Title, ContentDocument.CreatedDate,LinkedEntityId
FROM ContentDocumentLink where LinkedEntityId='5005000000qtXXXXX'  

 
This was selected as the best answer
Mike Bucci 6Mike Bucci 6
Awesome.  Worked perfectly. Thank you!!!