0

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

3

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.Id=null;
        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? – Eugene Vabishchevich Nov 29 '18 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 – Pranay Jaiswal Nov 29 '18 at 14:52
  • it doesn't work if I use attachment in feeditem – Eugene Vabishchevich Nov 30 '18 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 – Pranay Jaiswal Nov 30 '18 at 10:55
  • that was the reason of the question :) i don't know exactly what the table I should to query. – Eugene Vabishchevich Nov 30 '18 at 10:59

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.