I am trying to clone File(s) from a parent object to child. The code I am using is doing that but the file type is set to "LINK" while doing so, and I am unable to open that file or it has nothing when I open. Below is my code. Please help me out.
Thank you.
set<Id> contentDocIDList = new set<Id>();
for(ContentDocumentLink conDocLink : [SELECT ContentDocumentId,Id,IsDeleted,LinkedEntityId,ShareType,SystemModstamp,Visibility FROM ContentDocumentLink WHERE LinkedEntityId = :parentobject.id]){
contentDocIDList.add(conDocLink.ContentDocumentId);
}
VersionList = new List<ContentVersion>();
VersionList = [select Title, Description, FileType,Owner.Name, VersionNumber,CreatedDate,FileExtension from ContentVersion
where ContentDocumentId in :contentDocIDList AND IsLatest = true];
for(ContentVersion objAttach : VersionList)
{
for(ContentVersion objIndividualAttachment : [select id, Title, Description, FileType,Owner.Name, VersionNumber,CreatedDate from ContentVersion where Id = :objAttach.Id])
{
ContentVersion con= new contentversion();
con.ContentLocation = 'S';
con.PathOnClient = con.Title;
con.ContentUrl = '/'+childobject.id;
con.Title = objAttach.Title;
insert con;
con.VersionData = null;
Id conDoc = [SELECT ContentDocumentId,Title FROM ContentVersion WHERE Id =:objA1.Id].ContentDocumentId;
/
ContentDocumentLink CDL = new ContentDocumentLink();
CDL .ContentDocumentId = conDoc;
CDL .LinkedEntityId = newco.Id;
CDL .ShareType = 'I';
CDL .Visibility = 'AllUsers';
insert CDL;
}
}
}