0

I just created a lightning component + quick action to clone a case (It's working). But i want to link the attachement of the old case to the new one (I don't want to clone it). i tried with ContentDocumentLink but i can't retrieve the fields that i need. Any ideas?

I tried to do this :

enter image description here

  • 2
    Hi Yanis, could you edit your question to show what you tried so far and how it's not working? Also, any time you're dealing with Attachments, you need to make sure you're clear about whether it's the Attachment sObject or the Content system - if one is being used and your code looks for the other, nothing will happen. – David Reed Mar 25 at 13:45
  • 1
    Can you edit your question and paste your code in text instead of an image? Also when you say you cannot retrieve the fields, what issue do you see? – Jayant Das Mar 25 at 14:07
1

With what I see in the image for the code snippet, you have a query as below:

[SELECT .... FROM ... WHERE LinkedEntityId = 'recordId'];

Seems, that is your issue where you are not able to retrieve the contents for that particular record as you have the text value in there instead of the Id expected.

Your query should instead look like as below where you will need to bind the recordId to be able to fetch the values.

[SELECT .... FROM ... WHERE LinkedEntityId = :recordId];
0

I just found how to do the Link without cloning the Files: (Actually my Id is in a string):

List<ContentDocumentLink> doc= [SELECT Id, LinkedEntityId, ContentDocumentId, Visibility, ShareType FROM ContentDocumentLink WHERE LinkedEntityId = 'recordId'];
 
       List<ContentDocumentLink> newDoc= new List<ContentDocumentLink>();
        if (doc.size() != 0){
            for(ContentDocumentLink c : doc){ 
                ContentDocumentLink contentlink=new ContentDocumentLink();
                contentlink.LinkedEntityId=clondedParentRecordID.Id;
                contentlink.ShareType= 'V';
                contentlink.ContentDocumentId=c.ContentDocumentId;
                newDoc.add(contentlink);
            }
        }
        if(newDoc.size()!=0)
        {
        insert newDoc;
        }  

We have to use the object DocumentContentLink that create a link between the Sobject and the Files (ContentDocument Object).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.