I want to copy files (not attachment sObject) from old case to the new one as feeditem. What sObjects should I copy?


1 Answer 1


Why clone files and increase file Storage when you can link same file to multiple cases.

The junction Object from Case and File is called as ContentDocumentLink.

So what we can do is create another link of that file for new case.

public static void cloneFilesFromOldCaseToNew(String oldCaseId ,String newCaseId ){
    List<ContentDocumentLink> toBeClonedContentDocumentLinks = [SELECT ContentDocumentId,Id,IsDeleted,LinkedEntityId,ShareType,SystemModstamp,Visibility FROM ContentDocumentLink where LinkedEntityId=:oldCaseId];
    for(ContentDocumentLink cdl : toBeClonedContentDocumentLinks){
        cdl.LinkedEntityId = newCaseId;

    insert toBeClonedContentDocumentLinks;

Src: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentdocumentlink.htm

  • good point! Is it ok to do cloning with the same record but empty id field? Nov 29, 2018 at 14:50
  • when you do a clone and create a new record, its has a new ID. I made the Id as null so that I can use insert command. Insert command only works if there is no ID. After inset a new record will be created and new ID will be associated Nov 29, 2018 at 14:52
  • it doesn't work if I use attachment in feeditem Nov 30, 2018 at 10:54
  • It is for SF files only, You have to investigate for FeedItem attachment as its a different table so different query and approach Nov 30, 2018 at 10:55
  • that was the reason of the question :) i don't know exactly what the table I should to query. Nov 30, 2018 at 10:59

You must log in to answer this question.

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