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
ViswaViswa 

query file/attachment based on RecordId

How can we get FIle/Attachment With the help of recordid
Best Answer chosen by Viswa
Seemu Saikia 4xSeemu Saikia 4x
Let say your id is 'a091C00002EQnnT'

To get attached file refer to ContentDocumentid . Use the below SOQL query. 
List<contentDocumentLink > listCDL = [ SELECT ContentDocumentid, LinkedEntityid FROM contentDocumentLink WHERE LinkedEntityid = 'a091C00002EQnnT'];

Set<Id> setContentDocumentIds = new Set <Id>();

for( contentDocumentLink  rec : listCDL  ){

     setContentDocumentIds .add(rec.ContentDocumentid);
}
To get the content version you can further use : 
 
List<ContentVersion > listContentVersion  = [SELECT Id  FROM ContentVersion  WHERE ContentDocumentId IN :setContentDocumentIds];