Im creating the instance of the ContentDistribution for each Contenversion ids. and I'm referring this ContentDistribution's ID in VF page as a URl but its not working. So what I want is when a user generates the PDF of a Case Record in that PDF I should provide all the attached Files/attachment link so that when the user clicks on it. it should navigate him to that Particular Attached file --- The Apex Controller
public class CaseInformationForPDF {
ApexPages.StandardController standardController;
Public Case caseRecord{get;set;}
public string recordID ;
Public List<ContentVersion> contentVersionRecords{get;set;}
public string pdfView {get;set;}
Public list<ContentDistribution> contentDistributionRecords {get;set;}
Public list<ContentDistribution> contentDistributionQueriedRecords {get;set;}
Public list<ContentDocumentLink> contentVersionRecordsDocumentLink {get;set;}
Public Set<id> contentDocumentIds {get;set;}
public CaseInformationForPDF ( ApexPages.StandardController standardController ) {
Try{
this.standardController = standardController;
recordID = standardController.getId();
contentVersionRecordsDocumentLink =[SELECT id,ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId =:recordID];
contentDocumentIds = New Set<id>();
for(ContentDocumentLink contentDistributionRecord : contentVersionRecordsDocumentLink)
{
contentDocumentIds.add(contentDistributionRecord.ContentDocumentId);
}
contentVersionRecords =[SELECT id,Title,ContentDocumentId,VersionData FROM ContentVersion WHERE islatest=true and ContentDocumentId in :contentDocumentIds];
contentDistributionRecords = New list<ContentDistribution>();
If(contentVersionRecords.size()>0){
for(ContentVersion cont : contentVersionRecords){
ContentDistribution contentDistributionRecord = new ContentDistribution();
contentDistributionRecord.name = cont.Title;
contentDistributionRecord.ContentVersionId = cont.id;
contentDistributionRecord.PreferencesAllowOriginalDownload = true;
contentDistributionRecord.PreferencesAllowPDFDownload = true;
contentDistributionRecord.PreferencesAllowViewInBrowser = true;
contentDistributionRecords.add(contentDistributionRecord);
}
}
}
catch(exception e)
{
system.debug('message -- '+e.getMessage()+ 'line. - '+e.getLineNumber()+'cause. ' + e.getCause());
}
}
public void contentDistributionMethod()
{
contentDistributionQueriedRecords = New list<ContentDistribution>();
IF(contentDistributionRecords.size()>0)
{
Insert contentDistributionRecords;
contentDistributionQueriedRecords = [SELECT DistributionPublicUrl,name,Id FROM ContentDistribution WHERE ID in :contentDistributionRecords];
}
}
Visual force page
<apex:page showHeader="true" standardController="Case" extensions="CaseInformationForPDF" standardStylesheets="true" renderAs="PDF" action="{!contentDistributionMethod}">
<apex:form >
<body>
<ul>
<apex:repeat value="{!contentDistributionQueriedRecords}" var="attachment">
aaaa <li> <apex:outputLink value="/{!attachment.DistributionPublicUrl}" id="theLink">{!attachment.name}</apex:outputLink></li>
</apex:repeat>
</ul>
Can anyone guide me on this?