Introduction

While you can insert static images into your templates, S-Docs can also insert dynamic images. For example, say you want to create a letter that includes an image of the representative’s signature at the bottom of a page. Or similarly, you may want to include an image of your product on a Product Specifications PDF. Rather than cloning the same template many times (once for each unique image), you would rather have just one template that dynamically includes the right image. You can accomplish this in several ways.

Option 1: Use a rich text field

This is perhaps the easiest method. You first upload your image into a standard Salesforce rich text field on your record detail page. Then, open the template in which you want to add the image, click on the Template Editor button, click on the Insert Field button, select the rich text field, click on the Contains Rich Text checkbox, and finally click on the Insert button. Your documents will now render the rich text content for that record wherever you placed this field.

Note: This option is only available for PDF-formatted documents. If your rich text contains many items or elements, it may not render precisely. This is because Salesforce uses a rich-text editor that auto-formats rich text content and this formatting cannot be overridden through a source editor. It is a better practice to use the S-Docs editor to control document layout rather than inserting a complex rich-text field into a template. By doing so, you also maintain template formatting in a central location (the S-Docs template) versus fragmented design elements located in rich text fields throughout individual records.

Option 2: Use a standard text field that contains the entire image markup

You can also use a standard Salesforce text field whose value contains the complete image element tag that you want to include. Each record would potentially contain a different link that corresponds to the applicable image.

For example, set the value of a ProductImage__c field on a Product record to:

Then, using the S-Docs template editor, click on the Insert Field button, select the field, and then be sure to click on the Contains Rich Text checkbox.

This is a simple approach but has limited usage. It is useful for images such as representative signatures, where they are centrally controlled by an administrator, they do not change frequently, and the user would not normally need to view them in the Salesforce user interface along with the record. Since this is a text field, if you were to include this field on a page layout, it would not render as an image – users would only see the text shown above when viewing the record detail in the Salesforce UI. Therefore, it would not be appropriate for end-users who upload their own images frequently (e.g. a scanned photograph of a damage claim) or wanted to view the actual image in Salesforce within the record detail page.

Option 3: Use a formula field to display an image

Building on option 2, you can leverage a Salesforce formula field to create the image path and also display the image within the Salesforce record detail. You would then drop the formula field into your S-Docs template with the Contains Rich Text option checked (as described in the previous option). The formula field would contain something similar to the following:

This option requires some planning so that the image field name can be programmatically derived.

Option 4: Build an image URL within the S-Docs template

This is a combination of options 2 and 3, but would not require a formula field. You can use a record’s existing field value to help build the correct image path, but you create the full path value within the S-Docs template, not in the Salesforce field.

For example, to include a dynamic product image or agent's signature, you can use something similar to the following in your document template source:

The field value should be a URL that points to either an image in your Salesforce documents folder or an external image hosted on the public internet. In the second example, the field should contain the entire path including the ‘http://’ prefix.

Since the image path is text (not markup) it should only be surrounded by double curly braces, as shown above. The special notation for  <, >, and quotes, using lt#, gt#, quot# respectively, is used to instruct S-Docs that this markup needs to be evaluated rather than rendered literally. Having this flexibility gives you total control of how you want a field interpreted within the S-Docs template.

In order to compensate for relative URLs (e.g src=“/servlets/…”) that Salesforce automatically generates, S-Docs will automatically replace the relative path with the complete path, including the correct Salesforce.com instance (e.g. src=”https://na1.salesforce.com/servlets/...”). Doing this ensures your embedded images render correctly when viewed by others. If you wish to override this behavior and use a relative URL, you should specify the path to include the “http” (e.g. src=”http://servlet/”).

Discussion

Once you have inserted a marked-up field into your template, you will notice three sets of braces that surround your field, for example:

The extra pair of curly braces instructs S-Docs to interpret this field rather than just displaying the stored value. Without this, S-Docs would not know whether a field containing the value “<img src=“//host/Product123Image.png” />”  should be displayed as the text quoted or substituted with the actual image when rendered. Whenever you add a field using the template editor and click on the Contains Rich Text checkbox, S-Docs will evaluate the value regardless of the actual Salesforce field type (Rich Text or otherwise).

If images outside of Salesforce are used in the S-Docs template directly, or dynamically through a merged image field, you must whitelist the URL domain (using Setup > Remote Site Settings) to avoid broken image icons in the PDF.