...
The actual SOQL queries can be entered either manually or by using the powerful query builder. In most cases the query builder should be chosen. Only for complex queries with sub queries the manual entry flag should be selected.
Using Query Builder
...
If the query builder is used (i.e. checkbox “Manual Entry” NOT checked), the sub-tab “Query Builder” shows two sections:
...
If for some reasons, you need to create queries including subqueries, the query needs to be entered manually.
When entering queries manually the query builder cannot (and should not) be used anymore for this query.
The queries need to be entered as a JSON data array: [{ Query 1} , { Query 2 }, … ]
Here is an example of a manually entered query (and data mapping) including a subquery:
Data Queries:
[
{
"name": "AccountQuery",
"singleRecord": true,
"query": "SELECT For example to enter the query: “SELECT Name, (SELECT FirstName, LastName, Email FROM Contacts) FROM Account WHERE Id = :recordId",
"mapping": {
"AccountName": "Name",
"ContactRecords": "Contacts.records"
}
}
]recordId“ manually do the following steps:
Add a new Query in the QueryBuilder and name it appropriately
Select the SObject of the main Query, e.g. “Account”
If it is a single record query, select the “Single Record” checkbox
Check the “Manual Query” checkbox
Enter the SOQL Query manually
Add the fields mappings for the fields from the main query and for the subquery records (e.g. Contacts.records where “Contacts” is the name of the subquery relation
Please be aware that you can only map the fields from the main query. The subquery fields need to be used as they are returned from SOQL.
...
A corresponding docx template might look like this:
...
Create the IdealDoc Template
...
After creating a new IdealDoc template record the detail record screen looks like this:
...
Template File (docx)
Under the “Details” sub-tab the previously entered meta data can be edited. In the “Files” section the actual Word (docx) template file should be uploaded. For a reference on how to create a valid Word (docx) template please see Word Template Reference v2 or Word Template Reference v1 .
IMPORTANT: Only template records that contain at least one file will be available in the document generation. Always the last recently uploaded or modified File will be used when creating a document!
Here a list of the most important template expressions:
Template Configuration:Single Fields:
Merge fields in IdealDoc are defined as regular text enclosed in double curly brackets. This example shows the usage of some single merge fields with various formats (text, link, number, date, dateTime):
Code Block | ||
---|---|---|
| ||
Industry: {{Industry}}
AnnualRevenue: {{number AnnualRevenue}}
# Employees: {{number NumberOfEmployees}}
Created Date: {{date CreatedDate}}
Owner: {{OwnerName}}
Last Modified Date: {{dateTime LastModifiedDate}} |
Link/Url Fields:
Code Block |
---|
{{link url=Website label="Company Website"}} |
Image:
Code Block |
---|
{{ image url=LogoUrl width="4" alt="No Image Found" }} |
Richt Text Field (simple and with fix image sizes):
Code Block |
---|
{{html Description}}
{{html (replace Description 'img src=' 'img width="2" src=')}} |
Conditional rendering
Code Block |
---|
{{@p#if Contacts.length }}
Show contacts information
{{@p else}}
No Contacts
{{@p/if}} |
In this example, the “Contacts” variable refers to a multi record query (list) named “Contacts”. If the length of the Contacts list is greater than zero the information about the contacts should be shown and otherwise “No Contacts” will be displayed.
The @p expression before the #if, else and /if stands for (@ paragraph) and makes sure that the templating engine removes the whole command line after evaluating the expressions. I.e. there are no empty lines displayed. That’s usually what a user wants when the text spans multiple lines.
If the whole expression will be written on a single line and should always display a text, the @p directive should be omitted. Here an example where if the “Language” variable is empty, “English” will be displayed and otherwise the value of the “Language” field:
Code Block |
---|
{{#if (empty Language)}}English{{else}}{{Language}}{{/if}} |
for a negative condition (if not), the “unless” expression can be used:
Code Block |
---|
{{#unless (empty Language)}}English{{else}}{{Language}}{{/unless}} |
Loops:
Looping through the Contacts query, displaying first and last name of each contact and removing the command lines 1 and 3 after rendering (ensured by @p)
Code Block |
---|
{{@p#each Contacts}}
{{FirstName}} {{LastName}}
{{@p/each}} |
To display all contacts on a single line:
Code Block |
---|
{{#each Contacts}}{{FirstName}} {{LastName}},{{/each}} |
Tables:
A very common use case when using IdealDoc is to display dynamic tables.
Nr / Total | First Name | Last Name |
---|---|---|
{{@tr#each Contacts}}{{add @index 1}}/{{../Contacts.length}}{{@tr/each}} | {{FirstName}} | {{LastName}} |
With the @tr#each and @tr/each the loop commands will be placed before and after the table row, ensuring that for each contact a new table row gets displayed. Within a loop context, a global variable called @index is available, containing the zero based index of the current loop element. If a row numbering starting at 1 should be shown, the {{add … }} command can be used to add one the the zero based index.
For a query variable like “Contacts” there exists a property “length” which contains the number of records in this query result. To access this Contacts.length property from within a loop context, the ../Contacts.length expression needs to used. The ../ navigates one level up to the root context containing the Contacts variable.
Template Configuration
On the “Configuration” sub-tab, template specific configuration settings can be defined:
...
Decimal Delimiter:
Static Data:
Create an Action Button
To allow the end user to call IdealDoc and create a merge document, a predefined Salesforce screen flow called IdealDocGenericActionScreenFlow can be used.
Because it is currently not possible in Salesforce to pass dynamic parameters to a flow from a quick action (a feature which will be hopefully added by Salesforce in future release), a simple naming convention for the quick action has been defined.
To pass the IdealDoc environment and the information which category of IdealDoc templates should be available for selection the name of the quick action button has to follow a certain naming convention. An example quick action definition looks like this:
...
The name of the quick action needs to comply with the following pattern:
<Any Name>_<Attach to SF (attach or noattach)>_<Format (pdf or docx)>_<DialogType (single or multi)>_<IdealDoc Template Category>_<IdealDoc Setting Data Name>
for example: CreateIdealDoc_attach_pdf_single_Invoice_prod
The IdealDoc Template Category (“Invoice” in this example) will be used to show only the IdealDoc Templates with Category equals to “Invoice” for selection. If no template filter should be applied the term “any” can be used as category. E.g. CreateIdealDoc_single_any_prod
The IdealDoc setting name (“prod” in this example) is used to query the IdealDoc Setting record with this name for connecting to the IdealDoc service.
After creating the quick action it needs to be added to the specific lightning page:
Once added to the lightning record page the action button can be used to create the IdealDoc document:
...