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 permission setup, please refer to this page.

Create a template file

Prepare a Word file. This article creates a template file using the following invoice file as an example. The records to be output are Opportunity as the master 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}

Product 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 row of the child object's merge fields, delete the second and subsequent rows. In this example, rows No. 2 through No. 10 are deleted. When outputting, the number of rows 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 the merge field for the output date in the header. Set Office File Creator's function {!Today()} as the merge field. The {!Today()} function is available in Office File Creator Ver. 2 and later.

 

Memo

The {!Today()} function has been available since Office File Creator 2.0.

 

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.

You can check the contents of a Word field code by pressing "Alt" + "F9".

 

The template file is now complete.

 

Create a template record and custom button

Create template records and custom buttons as in the 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