Output attached images in Salesforce to documents

This article introduces the procedure for outputting attached images in Salesforce to documents in Office File Creator.

* This feature is available in Office File Creator Pro.


Output Sample

As an example, output the attached image of the Opportunity to Excel.


Excel file after output




Merge Fields Settings

Set "ContentDocument" to the object and "Id" to the field of related file.

For Memos & attachment objects in Salesforce Classic, set "Attachment" to the object.

Set "No.", "Title", and "Id" for the merge field.

No.: {!Number()}

Title: {!ContentDocument.Title}

Image: {!ContentDocument.Id}



Create OFC_Template Record

Create an OFC_Template record and upload the template file.



Create OFC_Child Object Option Record

Create a record from the "New" button on the "Child Object Options" tab of the OFC_Template record screen.



For the child relation name, enter "ContentDocument" for File and "Attachment" for Memos & attachments.

Name: Enter any name. In this case, enter "File".

Child Relationship Name: ContentDocument


Sort Order

Sets the ascending order of Title.

SortField1 API Name: Title

SortField1 Order: Ascending (NULLS LAST)


(Pro) Filter Criteria (ContentDocument/Attachment)

Output jpg, jpeg, and png file extensions (FileExtension).

(File) FilterCriteria Field API Name: FileExtension

(File) FilterCriteria Operator: IN

(File) FilterCriteria Value: jpg,jpeg,png

*Retrieve multiple conditions with "IN". Enter criteria values, if multiple, separated by commas.


(Pro) Image

Enter the "Id" set for the merge field.

Image Field API Name: Id



OFC_Template Record Settings

Set the margins in Excel cells. Size settings are set in OFC_Template for all the master object, child objects, and attachments. The placement of images in Excel is based on the upper left corner, so set the top, bottom, and left margins.


(Pro) Image

In this case, use the default 3.0 for all here, so leave all blank.

(Excel) Image Cell Margin (Top) (pt): If left blank, the default of 3.0 pt is applied.

(Excel) Image Cell Margin (Bottom) (pt): If left blank, the default of 3.0 pt is applied.

(Excel) Image Cell Margin (Left) (pt): If left blank, the default of 3.0 pt is applied.


Explanation of margins


The image size is determined based on the cell height. It is placed based on the upper left corner and cannot be centered on the left or right.


Output File

The setup is now complete.

Output file




When a image file size exceeds 4.28 MB

Images with a file size of up to 4.28 MB per image are output. If the file size exceeds 4.28 MB, error image data will be displayed in the output file.

4.9MB image output


The error image "This picture cant be displayed." is output for the merge field.



When Lightning Web Security is enabled

When outputting images in Excel or Word, if your organization has Lightning Web Security enabled, output from a custom button. If you output from the Lightning Component button or flow, the file will take significantly longer to output.


Lightning Web Security Settings can be found from the Setup > Security > Session Settings > Lightning Web Security section under "Use Lightning Web Security for Lightning web components and Aura components".

*For more information about enabling or disabling Lightning Web Security for your organization, contact your organization's system administrator or Salesforce Help.


Use the "Export to File (Custom Button)" button during test output.


In this example, four files between 2.9 MB and 3.7 MB are output. The file size after output is 12.5 MB. When Lightning Web Security is enabled, the processing times for output with each of the custom buttons and Lightning Component buttons are as follows.

Processing time

Custom button ・・・ 8 seconds

Lightning Component button ・・・ 48 seconds


File List


Output from the custom button


8 seconds


Output from the Lightning Component button


48 seconds




Refer to Output Images for limitations and considerations when outputting images.