Generate a Word document in Salesforce using Office File Creator

This article is a step-by-step guide to setting up the output of word documents in Salesforce using Office File Creator, along with examples. The main step is template file creation. For installation and authorization procedures, please refer to this page.

 

Create a template file

Prepare an word file. In this article, I will create a template file using the following invoice file as an example. The records to be output are Opportunity as the primary object and Opportunity Product as the related object.

 

Set the Account Name, Date, Invoice No., Opportunity Name, and Total. Fields ending with the API name "__c" are custom fields. Since the Total is currency type, set the $ sign to the beginning of the merge field.

Account Name: {!Opportunity.Account}

Date: {!Opportunity.BillingDate__c}

Invoice No.: {!Opportunity.BillingNumber__c}

Opportunity Name: {!Opportunity.Name}

Total: ${!Opportunity.TotalIncludingTax__c}

 

Memo

In the Salesforce record detail screen, the currency type will include a currency symbol such as the $ sign, but Office File Creator does not output the currency symbol.

 

Next, set up the merge field for Opportunity Product of the related object of Opportunity. The table of Opportunity Product is styled in the table style of Word's table design with striped rows.

 

The child relationship name for Opportunity Product is OpportunityLineItems. Set each of the merge fields on the first row. Since the Price and Subtotal are currency type, set the $ sign to the beginning of the merge field.

Product: {!OpportunityLineItems.Product2}

Code: {!OpportunityLineItems.ProductCode}

Price: ${!OpportunityLineItems.UnitPrice}

Quantity: {!OpportunityLineItems.Quantity}

Subtotal: ${!OpportunityLineItems.TotalPrice}

 

Set Office File Creator's function {!number()} to set sequential numbers in the first column No. The {!number()} function can be used to set the sequential numbers of child records in the output order.

 

After setting the first line of the child object's merge fields, delete the second and subsequent lines. In this example, lines No. 2 through No. 10 are deleted. When outputting, the number of lines corresponding to the number of records of the Opportunity Product is output.

 

Next, set the Subtotal, Sales tax, and Total for Opportunity. Since all of these are currency type, set the $ sign at the beginning of the merge field.

Subtotal: ${!Opportunity.SubTotal__c}

Sales Tax: ${!Opportunity.Tax__c}

Total: ${!Opportunity.TotalIncludingTax__c}

 

Next, set the Installation Support. Installation Support is created as a custom field.

Installation Support: {!Opportunity.IsInstallationSupport__c}

 

Next, set up the merge field for the output date in the header. For the created date is created a formula field Today__c of Today().

 

Memo

Salesforce Classic email templates allow Salesforce functions to be used as the merge field, such as {!Today()}, but Office File Creator does not allow Salesforce functions to be used as the merge field.

 

The footer is set to "page number/total number of pages" in the Word field code. When outputting the file, if there are multiple pages, they are output as is as 1/3, 2/3, 3/3, etc.

 

The template file is now complete.

 

 

Create a template record and custom button

Create template records and custom buttons as in the previous Excel version. See below for detailed instructions.

Generate an Excel file in Salesforce using Office File Creator – (2) Create a template record

Generate an Excel file in Salesforce using Office File Creator – (3) Create custom buttons

 

A sample file output is shown below.

 

The template file created in this article can be downloaded below.

 

Copied title and URL