We're going to go through 3 simple steps to achieve this:
Creating multiple tables in a document
Filter these tables to show only relevant data
Sort tables by the criterion of your choice
Prerequisites
BEFORE STARTING
Have a template already ready with the main object configured
Take a use case where the main object has many related elements (e.g.: Opportunity, Quote, Account,...)
Why do tables?
A table corresponds to a related list in Salesforce. For example, if I am on an account, the contacts are children of the account. If I find myself on an opportunity, the opportunity products are children of the opportunity.
These relationships can be standard or built using custom objects. Gonexa technology will simply allow you to display information related to your context.
Many use cases are possible such as displaying the products, services, and options related to my business opportunity in 3 separate tables in my document even though they are all in the same Salesforce object (ProductLineItems).
Create tables
STEP #1
Add child objects to Salesforce
Repeat the operation several times with a correctly named label each time (ex: Label #1 = Product, Label #2 = Service, Label #3 = Option”)
We end this part by clicking on “Access tags” in order to facilitate the insertion of tags in the final document.
Inserting tables in Word
This step is based on standard tables offered by Word. For more simplicity, feel free to use our pre-designed templates available on our website.
Insert a new table with 2 rows and the number of columns you want
The first line will allow you to have the names of the columns, name the columns as you want
On the 2nd line, we are going to use the Wizard that we opened earlier to put the tags
Click on the desired child object and look for the field according to what you want to put in your table
Finalize the template with all the fields you want to see displayed
To make it easier to understand, you can download the template shown during the demonstration below:
Template upload and testing
Go back to Salesforce and upload the Word template with the tables by clicking on “Upload version”
Make sure you have a test record with children
Test the generation to see the final result
Filter data
STEP #2
Filters ensure that you only see data that is relevant to your context. Here, we want to filter only the “Product” category in the 1st table, the “Services” in the 2nd, and the “Options” in the last. We use the same Salesforce object 3 times but with different views.
Identification of the filter to be used
Knowledge of your Salesforce is essential to know the right filter to use and who will be the one fed with the right data.
If the field that can filter the data has not yet been created, you must create it and ensure that it is populated.
Addition of the condition on the child object
In the Gonexa Assistant component, edit the child object by clicking on the pencil
In the “Filter” section, add a record retrieval filter
Find the field to use for the filter
Indicate the operator and the expected value (ex: Product family = Service)
Checking the filter
Go back to your context (Quote, Opportunity,...)
Make sure you have completed data on the filtered field
Generate to verify that the filter has been applied
Sort data
STEP #3
This step is optional since it will simply improve the organization of the data in your table a bit at the time of generation.
Identify the sorting criteria
Add the filter to the child object
Go back to the child object you want to sort
In the “Sort” section, specify the field you want to sort with
Choose sorting order from Ascending or Descending
Example: ascending sorting of the ProductCode field
Sorting check
Go back to your context (Quote, Opportunity,...)
Make sure you have the data filled in on the sorted field
Generate to verify that the sorting has been applied
Grouping data
STEP #4
Group items according to a Salesforce criteria
Group all the elements of a child object that correspond to a criterion, that is, group the rows of a table in a Word document according to a Salesforce field such as the family of a product for example.
From the child object of your document template:
Choose the Salesforce field to group on. It can be an object based on the child object or on a parent object of the child object.
Example: Product2.Family
Name the field “Group Name” in any way you want.
Example: Group
From your document template, build your table using one of the following two methods.
Method 1: If you don't want to repeat table headers [SIMPLE]
From your Word document template, create a table with one column and two rows, with the first row containing the name of the group.
{!Group name|Api name of the field to group on}
Example: {!Group|Product2.Family}
In the 2nd row of the table, insert the entire table. (Header, columns, and rows) containing child objects
Adjust borders and columns to suit you using Word formatting.
Download an example template
Method 2: If you want to manage the repetition of headers on several pages. [ADVANCED]
From your Word document template, create a table with one column and three rows, from which, in the first line, you will fill in the grouping tag.
{!Group name | Api name of the field to group on}
Example: {!Group|Product2.Family}
In the 2nd row of the table, split the cell according to the number of columns you want
In the 3rd row of the table, insert the table of your child object containing the child tags, adjusting the columns as well as the borders. You can also change the properties of the table by choosing the value “Around” as “Text wrap”.
The table (in its entirety) will be repeated according to the number of results that correspond to the criterion and with the name of the family in the header.
Word configuration vs Generation result
Download an example template