Add Dynamic Images

Introduction

While you can insert static images into your templates, you can also insert dynamic images. For example, 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.

Note: If images stored outside of Salesforce are used in your S-Docs template directly, or dynamically through a merged image field, you must create a remote site setting for the image's URL domain (using Setup > Remote Site Settings) to avoid broken image icons in the PDF.
Note 2: If you are working with images stored in Salesforce, we recommend pointing image references in your sandbox templates directly to image URLs in your production org. If you do this, you won't need to update any of your images once you move your sandbox templates into your production org.

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 and DOCX 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:

PRODUCT IMAGE:<br><img src=”/host/Product123Image.png” />

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:

IMAGE("/CompanyIntranet/Products”+ myObject__c.ProductID__c + “.png")

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:

lt#img src=quot#http://intranet/{{!Product2.ProductPath__c}}.png quot# /gt#
lt#img src=quot#{{!Opportunity.Owner.SignatureURL__c}}quot# /gt#

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. 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.

Note that Salesforce automatically generates relative URLs (e.g. src=“/servlets/…”), as opposed to full URLs (e.g. src=”https://na1.salesforce.com/servlets/...”). While S-Docs automatically adds in the correct base URL, images still may not appear for certain template formats (especially when you've migrated templates between orgs). We recommend building a full image URL in a custom field so that the base URL can be changed in one place if needed, as opposed to every template.

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:

{{{!Product2.ProductImage__c}}}

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).

Dynamic Images with the DOC Template Format

For DOC templates, in order to ensure that your images are scaled correctly in the final generated document, it is important to check Embed Images in the Page Settings tab of the template editor.

Additionally, the user must click Enable Editing in Microsoft Word for images to download in the generated document.

Tags: ,

Was this helpful?