0

I have a custom object (name: mediadata), I've stored some files in the different items at the custom object. How can I get the information about the files via query?

I use for attachments the query below, but it doesn't work for files.

List <mediadata__c> MDList = [SELECT Description__c, Topic__c, (SELECT Id FROM Attachments ) FROM Mediendata__c];

What is the structure from the files? I find something about the contentversion and ContentDocument but its not clear at the moment.

UPDATE

List <Mediadata__c> MediadataList = [SELECT Id, Description__c, Topic__c FROM Mediadata__c ]; 
    FOR (Mediadata__c MSI : MSList) { 
        List <ContentDocumentLink> CDLList = [SELECT Id FROM ContentDocumentLink WHERE LinkedEntityId = :MSI.Id]; MSList.addAll(CDLList); 
    } 
return MSList;

How can I combine my MediaDataList with the CDLList. Should I use a map?

2 Answers 2

1

Files are stored as ContentDocument records with ContentDocumentLink records acting as a many to many from a ContentDocument instance to a Linked Entity (a record, group etc).

If you query

SELECT ContentDocumentId, Id, LinkedEntityId, ContentDocument.Title FROM ContentDocumentLink WHERE LinkedEntityId = 'your record Id'

substituting in for your record Id you will get the list of files shared with that record. I have included their title as an example of what you can get from the ContentDocument object itself.

Available fields on ContentDocument can be found here and for ContentDocumentLink here.

1
  • thank for your response. but how can I use this in my case List <Mediadata__c>MediadataList = [SELECT Id, Description__c, Topic__c FROM Mediadata__c ]; FOR (Mediadata__c MSI : MSList) { List <ContentDocumentLink> CDLList = [SELECT Id FROM ContentDocumentLink WHERE LinkedEntityId = :MSI.Id]; MSList.addAll(CDLList); } return MSList;
    – peXeq
    Commented Aug 28, 2017 at 11:26
0

If you have attached files in your custom object, then you can query the attachments detail from the attachment Object, and passing the parentId as you Custom Object Id. For single mediadata record:

List attach = SELECT ContentType,Id,Name,ParentId FROM Attachment where ParentId = 'a0b28000003Ebgb';

Or even you can Query on your custom object and pass the complete list of Custom object.

List<mediadata__c> mediaDataList = [Select Name,Id from mediadata__c];
Set<Id> mediaDataIds = new Set<Id>();
for(mediadata__c m : mediaDataList) {
 mediaDataIds.add(m.id);
}    
List attach = SELECT ContentType,Id,Name,ParentId FROM Attachment where ParentId IN :mediaDataIds;

You must log in to answer this question.

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