Skip to main content
The code below was used to identify and create a list of attachments to a case in Classic.  Does anyone know how to convert this to Lightning, based on the fact that Attachments now are Files?  This is a subset of code used to auto-transfer attachments from one case to another.  But in Lightning, because this list is empty, the code is not working - no attachments are transferred.  When I try to do a simple Select from Attachment, nothing is returned.

 

      Map<Id,list<Attachment>> mapOfOldCaseWithAttach = new Map<Id,list<Attachment>>();

 

       

 

      list<Attachment> lstAtt = [Select id,name,ParentId,body from Attachment where ParentId IN:setOldCaseId];

 

      for(Attachment attch: lstAtt)

 

      {

 

        list<Attachment> lstTmpAttch = new list<Attachment>();

 

        if(mapOfOldCaseWithAttach != null && mapOfOldCaseWithAttach.containsKey(attch.ParentId))

 

        {

 

          lstTmpAttch = mapOfOldCaseWithAttach.get(attch.ParentId);

 

          lstTmpAttch.add(attch);

 

          mapOfOldCaseWithAttach.put(attch.ParentId, lstTmpAttch);

 

        }

 

        else

 

        {

 

          lstTmpAttch.add(attch);         

 

          mapOfOldCaseWithAttach.put(attch.ParentId, lstTmpAttch);

 

        }

 

      }
3 respuestas
  1. 28 ago 2020, 05:47
    Hi Brent, 

     

    This code will need to be refactored completely. Files work slightly differently to attachments, with this model:

     

    ContentDocument contains the high-level details of a file  such as its title. 

     

    ContentVersion is a child object of ContentDocument and contains the actual file data. 

     

    ContentDocumentLink connects a content document to any other record. 

     

    So unlike attachments, you can't query a content document or version directly for a record. You have to query the content document link to see what files exist on the record, then query the content version record to get the actual file body.
0/9000