I have a Pdf attachment which is linked to an object in a Package. The public site is also part of the package so I do not have acces to query all files. I want to be able to let a public site guest user download the Pdf. I am trying to add the attachment to files but I am not able to query the ContentDocumentId what am I missing?
Aggregations:0|SELECT ContentDocumentId FROM ContentVersion WHERE Id = :tmpVar1 LIMIT 1 Error: System.ListException: List index out of bounds: 0
Apex
Attachment Att = [SELECT Id, Name, IsPartnerShared,IsPrivate, OwnerId, body FROM Attachment WHERE ParentId = :cxsAtt.id and name Like '%.pdf' Limit 1];
ContentVersion cVersion = new ContentVersion();
cVersion.ContentLocation = 'S';
cVersion.PathOnClient = Att.Name;
cVersion.Origin = 'H';
cVersion.OwnerId = Att.ownerId;//Owner of the file
cVersion.Title = Att.Name;
cVersion.VersionData = Att.Body;
Insert cVersion;
List<ContentVersion> conDocument = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:cVersion.Id Limit 1];
ContentDocumentLink cDocLink = new ContentDocumentLink();
cDocLink.ContentDocumentId = conDocument[0].id;
cDocLink.LinkedEntityId = att.ParentId;//Add attachment parentId
cDocLink.ShareType = 'I';
cDocLink.Visibility = 'SharedUsers';
Insert cDocLink;
conDocument[0].ContentDocumentId
but you are usingconDocument[0].id
. May be thats the issue? Else, can you provide the error details also?