How to get a chatter "sharing via link" URL?

How to get a chatter "sharing via link" URL which can be accessed by anyone inside or outside of your company?

This can be achieved from the field "DistributionPublicUrl" in “ContentDistribution” object.

Step1:  Get the document ID from the object  "ContentDocument".

SELECT FileExtension,FileType,Id,IsArchived,IsDeleted,PublishStatus, SharingOption,SharingPrivacy,Title FROM ContentDocument where Id = '0694D0000008Ub4QAE'

Step2: Pass the ContentDocumentId value to the object "ContentDistribution".

SELECT ContentDocumentId, DistributionPublicUrl, Id FROM ContentDistribution where ContentDocumentId = '0694D0000008Ub4QAE'

The field "DistributionPublicUrl" will contain the URL which can be shared via a link to SFDC users and non SFDC users.

Popular Salesforce Blogs