I have below code to add content document versionData into standard attachment.
Map<Id, Blob> bodyContent = new Map<Id, Blob>();
List<ContentVersion> contentDocs = [SELECT Id, Description, title,versionData,ContentDocumentId FROM ContentVersion WHERE Id IN : contentIds];
for(ContentVersion cVersion : contentDocs){
bodyContent.put(cVersion.ContentDocumentId,cVersion.versionData);
}
for (ContentVersion attach : contentDocs) {
Attachment conAttach = new Attachment();
conAttach.ParentId = customAttach.Id;
conAttach.Name = attach.title;
conAttach.Body = bodyContent.get(attach.ContentDocumentId);
conAttach.Description = attach.Id;
attachmentListToInsert.add(conAttach);
}
I have created the standard attachment with contentDocument versionData successfully. But when I download the attachment it is downloaded as type file.
But I want to download the file extension. Could anyone please help me to resolve this issue?
FileExtension
value to the filename, e.g.conAttach.Name = attach.Title + '.' + attach.FileExtension