Skip to main content
Build the future with Agentforce at TDX in San Francisco or on Salesforce+ on March 5–6. Register now.

Create DOCX and PPTX Document Templates

Learning Objectives

After completing this unit, you’ll be able to:

  • Describe the types of tokens used in Document Generation and their syntax.
  • Create DOCX document templates in Document Template Designer.
  • Explain the types of data-mapping flows.

DOCX and PPTX Document Templates

Sophia’s team is happy with the web document template, and they also need to generate Word and PowerPoint documents with strict formatting and control over document rendering. Before Felix gets to work on the templates, let’s learn about embedded tokens.

Embedded Tokens

A token is a placeholder in a template that maps input data for dynamic generation. For .docx and .pptx templates, you can embed various types of tokens, such as for variables, repeating content, images, rich text, hyperlinks, and condition evaluations. 

Click each token type to learn more.

Let’s look at how Felix uses these tokens to build the new Microsoft Word .docx template.

Variable Token

The template needs to capture details like subscriber name, street, city, state, zip code, and country. Here’s an example of a subscription agreement template with embedded tokens for these variables.

Example Microsoft Word document template with variable tokens

In this example, the subscriber name is the name of the customer.

Final output document using a variable token

The generated document displays the account name, street, city, state, zip code, and country.

Repeating Content Token

The subscription agreement includes a section that lists all products; in this case, the telecom products that the customer is interested in ordering.

Repeating content token example

For this variable, Felix uses a repeating content token, which is in tabular format.

Final output document using repeating content tokens

The final output document includes a table with multiple rows of products to show those the customer is interested in ordering. 

Condition Evaluation Token

Contracts often need to include details on compliance, such as for import and export of products. In this example, export compliance only applies to customers who live outside the USA. Therefore, the Infiwave subscription agreement should only show this clause for customers whose shipping address is outside the USA.

To set this up, Felix creates a conditional clause.

Condition evaluation token example

To configure the clause, Felix uses a condition evaluation token in the document template. This way, the final output document for customers outside the USA includes the clause. For customers in all other countries, the clause is hidden. Remember, the condition evaluation token only works with true/false statements.

Template Creation

Now Felix uses the Document Template Designer to create the template.

  1. Go to the App Launcher, and open Document Template Designer.
  2. Click New. The Start New Template window opens.
  3. Enter a Name for the template, for example Quote Agreement Template.
  4. For Template Type, select Microsoft Word or Microsoft PowerPoint. The Token Mapping setting determines how you populate the tokens. You can use a Data Mapper or a custom class.
  5. For Token Mapping, select a method. For instance, choose Data Mapper if you want to use Data Mappers to create the mapping. A Mapping Data Mapper extracts tokens from the .docx or .pptx template and matches them to fields in Salesforce. Use the Quick Match function in the Data Mapper Designer to match the fields automatically and save time.
  6. Enter a Mapping Data Mapper Bundle Name to transform the data for use in tokens. The example screen shows the bundle name tranformQuoteDetails_v1. Document Template Designer UI displaying the Start New Template screen with the Template Settings and Attach File section
  7. Optionally, enter a Data Extract Data Mapper Bundle Name to retrieve Salesforce data for use in tokens. The example screen shows the name extractQuoteDetails_v1. You only need to perform this step if you’re using an OmniScript to collect data for the document template.
  8. For Usage Type, select Quote.
    This sets the applicable template for the object type.
  9. Drag the .docx or .pptx file from your computer into the Document Template Designer, or click Browse to find the file.
  10. Click Save Template Details.

The new Microsoft Word .docx template is ready.

Now Felix tests the template. 

Use the sample client-side OmniScript to generate a document. Then check the document to make sure it’s up to scratch. Use the Document Template Designer to troubleshoot and adjust the template until your documents are just right.

Data Mapping in Document Generation

So far, you learned about data mapping in the document-generation process, but you might want to know more about how data makes its way into your document. The Data Mapper and custom class token-mapping methods help make this happen.

Data Mapper Data Mapping

With Data Mapper as your token-mapping method, Data Mappers extract and map the data to the template fields. Felix’s document requires data, such as Account Name and Account Details, which is stored in Salesforce. To pull the data into his template, he uses a Data Mapper Extract to get it from the Salesforce database in JSON format. 

A diagram that shows the JSON-based document generation data flow and data mapping

The extracted JSON needs some work before Felix can use it. For each document template, he needs to use a second Data Mapper, which is a Data Mapper Transform, to reformat the JSON code to something the Document Generator can read.

Once transformed, the JSON code is ready to use as input for the document-generation OmniScript. When the end-user completes the OmniScript, voila! The final HTML Web, Microsoft Word, Microsoft PowerPoint, or PDF document is ready.

Custom Class Data Mapping

When you select a custom class as your token-mapping method, the process is similar to the Data Mapper Data Mapping, just a bit more advanced. 

A diagram that shows custom class data mapping flow

For Felix’s document template, he creates an Apex custom class independently, and this serves as JSON input to the document generation OmniScript. The final result is another unique, formatted Microsoft Word, Microsoft PowerPoint, or PDF document. 

We talked a lot about the document-generation OmniScript, but there’s more to the story. Let’s move on to see the other pieces of Industries Document Generation. 

Resources 

Share your Trailhead feedback over on Salesforce Help.

We'd love to hear about your experience with Trailhead - you can now access the new feedback form anytime from the Salesforce Help site.

Learn More Continue to Share Feedback