Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

How to create contentdistribution public link?

Asked by Buffy Heaton May 22, 2023 1.4K views 1 answer
Share

About this question

I have to create a public link for files. I have inserted 'ContentVersion' and 'ContentDistribution' and created 'DistributionPublicUrl'. I am able to create a public link ('DistributionPublicUrl') but once I open a browser file it opens but 'No preview available' option is coming on the screen. While the download option is there.

Please find my code below:

ContentVersion contentVersionRec = new ContentVersion(); contentVersionRec.Title = fileName; contentVersionRec.PathOnClient = '/' + fileName; contentVersionRec.FirstPublishLocationId = contactRec.Id; contentVersionRec.VersionData = EncodingUtil.base64Decode(base64File); contentVersionRec.IsMajorVersion = true; Insert contentVersionRec; //update public link on Task ContentDistribution cdl = new ContentDistribution(); cdl.ContentVersionId = contentVersionRec.Id; cdl.Name = fileName; insert cdl; ContentDistribution cd = [SELECT DistributionPublicUrl FROM ContentDistribution WHERE Id =: cdl.Id LIMIT 1];

Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.