[SalesForce] Generate a Public Accessible link from ContentDocument

My Client wants to upload Image files from Account and generate a link for this image file and save it in a custom field on Account. This link should be Public Accessible (access from outside without the salesforce login prompt).

I tried using the ContentDownloadUrl field on ContentDistribution object.

For this I wrote a simple trigger on ContentDocumentLink object.

My problem is that a record inserted to ContentDistribution object and ContentDownloadUrl field populated when only user manually share the file from "Share via Link" menu option.

Is there any way to automate this process? Just populate this Public Accessible link using a APEX trigger when user upload an image?

Note : client wants to put this link inside a <img src=""> tag of his another site.

Best Answer

If you're using these as content also sent from Marketing Cloud, you should be using Marketing Cloud Content Builder features including File Transfer Locations for Marketing Cloud Enhanced FTP Sites. Marketing Cloud tools will create the hyperlinks for you when you Create Content Blocks.

The source images, will not be accessible to external users if stored in the Account Object. Since you will be using the images for multiple purposes, I recommend you create a custom object to store them in. Create a custom hyperlink field in the Account Object if you want to display them on their related records. Let Journey Builder and other Marketing Tools do their parts separately when it comes to creating links for use with those particular tools. I don't think you're going to be able to create a single link from the Account to image that will serve for all your purposes.