+ Start a Discussion
Harsh P.Harsh P. 

get attachments related to record

Hello,

I have custom obj Order__c with some records and each records having some attachments.Order__c having field Order_No__c
For lightning cmp I have to show Order_No__c and It's related attachments like below table : 
Sr.No      Order No        AttachmentName
1              12xx               MyAttachment.jpg


Now,I need an help to write controller specially Query ?
Britto Fernandez 2Britto Fernandez 2
Dear Harsh,

Did you try using contentdocumentlink object to give you link between object and content ?

Are you using content object ?
Harsh P.Harsh P.
Yes. but there is no any relationship between contentDocumet and Order__c obj
Britto Fernandez 2Britto Fernandez 2
You have to create record in contentdocumentlink object.
Harsh P.Harsh P.
Can you help to write Query for this ?
 
Harsh P.Harsh P.
Also I do not want pass hardcoded Id of record.
 
Britto Fernandez 2Britto Fernandez 2
Ok, meanwhile are you using contentversion object to store document ?
Britto Fernandez 2Britto Fernandez 2
For reference, you can use query similar to below and linkedentityid will have row id of linked object. 
SELECT Id,
            LinkedEntityId,
            ContentDocumentId,
            Visibility,
            IsDeleted,
            ShareType,
            ContentDocument.Title,
            ContentDocument.createdDate,
            ContentDocument.FileType,
            ContentDocument.ContentSize
            FROM ContentDocumentLink
Harsh P.Harsh P.
I have try same with the filter LinkedEntityId='Order__c obj Id'. No any error but showing 0 records.