For the complete documentation index, see llms.txt. This page is also available as Markdown.

Images from Files

In order to add images from a Salesforce File, a Public URL must be created in order to download/use the File as an image in a generated document.

This can be accomplished manually, by pulling up the File record and clicking “Public Link”. Once this is done, right-clicking on the opened image and copying the link should provide a link that can be successfully pulled into a document during generation.

For clients who want to automate creating public links and using them in generated documents on the regular, this can be accomplished with Apex, directly inserting the File (ContentVersion) into the public link table (ContentDistribution) like so:

Apex
/* Getting ContentVersion file using ContentDocument Id */
ContentVersion file = [SELECT Id, Title FROM ContentVersion WHERE ContentDocumentId = '<Content Document ID>'].Id;

/* Creating ContentDistribution record */
insert new ContentDistribution(
   Name = file.Title,
   ContentVersionId = file.Id,
   PreferencesAllowViewInBrowser= true
);

Or perhaps a triggered Flow is preferable:

Be sure to:

  • Make sure public link base URLs are included in Remote Site Settings

  • Note that a “download URL” will effectively download an image for document generation

Last updated

Was this helpful?