I want to make a ContentVersion record publicly available using Apex.

I know I can get the DistributionPublicUrl value from the ContentDistribution object.

But I don't know how I should configure the ContentVersion so that the DistributionPublicUrl is generated?


Just create an instance of ContentDistribution by providing you ContentVersion and a Name and then query the DistributionPublicUrl.

ContentDistribution cdl = new ContentDistribution();
cdl.ContentVersionId = '0680DXXX002RmxQAE';
cdl.Name = 'PublicShare';
insert cdl;

cdl = [SELECT DistributionPublicUrl FROM ContentDistribution WHERE Id = :cdl.Id LIMIT 1];
return cdl.DistributionPublicUrl;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.