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
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.