Share via Link :Public Link

? How to get a Public link through Apex

You have created a record on opportunity and attached a document

In order to share the document to the user who doesn’t have an access to Salesforce you have generated a public link and now you want to show use in apex

Following query can be used to get the public link

Select Id,name, DistributionPublicUrl FROM ContentDistribution

DistributionPublicUrl will give you the link. You will not get the link is you have not clicked on create link and generated the link