Skip to main content

Template Builder

A managed package Flow Screen component that gives users a point-and-click way to build document templates inside the Keelstone sidebar — without typing merge tokens by hand. Users browse Salesforce objects, select fields, and insert tokens directly into the open Word, Excel, or PowerPoint document.

Package: Keelstone Actions (managed, namespace kstone)
Component name: kstone__templateBuilder
Flow target: lightning__FlowScreen
Recommended launch target: Taskpane (sidebar)


What it does

The Template Builder inserts docxtemplater-compatible merge tokens into the template file the user has open in Office:

ActionResult inserted
Insert field{FieldName} at cursor
Insert related field (parent){RelationshipName.FieldName} at cursor
Insert loop table (child)A two-row table with {#RelationshipName}…{/RelationshipName} loop markers
Wrap condition (Word only){#field}…selected text…{/field} around a highlighted range

These tokens are the same syntax used by KS: Generate Document and the keelstoneGenerateDocument LWC — so templates built with this tool work directly with your existing generation flows.


Input properties

PropertyTypeRequiredDescription
keelstoneSessionIdStringYesKeelstone session token. Pass {!KeelstoneSessionId} from the flow variable.
documentTypeStringYesOffice app context: 'word', 'excel', or 'ppt'. Determines insert mechanics and which features are available.

Setting up the flow

Three flows ship with the managed package — one per Office app. Each flow has a single screen containing kstone__templateBuilder with documentType hardcoded as a non-input variable:

Flow API nameDocument TypedocumentType value
kstone__Template_Builder_WordWord / Docsword
kstone__Template_Builder_ExcelExcel / Sheetsexcel
kstone__Template_Builder_PowerPointPowerPoint / Slidesppt

Three Keelstone Action records are created automatically by the post-install job, pointing to these flows:

Action LabelDocument TypeLaunch Target
Template BuilderWord / DocsTaskpane
Template BuilderExcel / SheetsTaskpane
Template BuilderPowerPoint / SlidesTaskpane

The sidebar stays open while the user edits the document, so they can insert multiple fields in a single session.

If you need to create a custom flow (for example, to add pre-screen logic), create a screen flow with a single screen and wire both properties:

Flow variables:
KeelstoneSessionId (Text, Input = true) ← standard Keelstone variable

Screen → kstone__templateBuilder
keelstoneSessionId = {!KeelstoneSessionId}
documentType = 'word' ← hardcode per flow; do not use an input variable

Important: documentType must be set as a literal value in the flow, not as a flow input variable. The Keelstone platform does not pass input variables to Taskpane flows.


Features by app

Word / Docs

All three insertion modes are available:

Field insertion — browse any Salesforce object, search its fields, click Insert to place a single token at the cursor.

Loop table — browse into a child relationship (e.g. Contacts on Account), check multiple fields, click Insert as Table. The component inserts an HTML table with docxtemplater loop syntax:

| FirstName              | LastName                     | Email              |
| {#Contacts}{FirstName} | {LastName} | {Email}{/Contacts} |

When merged, each row in the related list produces one table row in the output document.

Conditional blocks — highlight a range of text in the Word document, then click + Wrap Condition in the sidebar. The condition panel appears with a field selector. Click Select Field… to open the condition picker.

Condition picker

The condition picker is a full-panel view that lets you navigate the object schema to select a condition field:

  • Fields — all accessible fields on the current object. Click Select to choose a field. Reference fields also show a drill button to navigate into the related object's fields.
  • Child Relationships — listed at the root level. Selecting a child relationship creates a count-based condition ({#Contacts | size > 0}…{/Contacts}).
  • Drill-down — you can follow parent reference fields up to 5 levels deep. A breadcrumb trail shows your current path.

Once you select a field, the condition panel shows the appropriate operators for that field type:

Field typeAvailable operators
Text, Picklist, IDIs present, Is absent, Equals, Does not equal
Number, Currency, PercentIs present, Is absent, Equals, Does not equal, Greater than, Less than, ≥, ≤
Date, DateTimeIs present, Is absent, Equals, Does not equal, After, Before, On or after, On or before
Boolean (Checkbox)Is true, Is false
Child relationshipCount greater than, Count less than, Count ≥, Count ≤, Has any records, Has no records

Click Wrap Selection to insert the condition tokens around the highlighted text:

OperatorInserted tokens
Is present / Is true / Has any records{#field}…{/field}
Is absent / Is false / Has no records{^field}…{/field}
Equals{#field == "value"}…{/field}
Does not equal{^field == "value"}…{/field}
Greater than (number){#field > value}…{/field}
Count greater than{#Contacts | size > 0}…{/Contacts}

Note: Conditional blocks use angular-expressions syntax. Operators beyond truthy/falsy require the angular-expressions plugin to be enabled in your Keelstone template configuration.


Excel / Sheets

Field insertion and loop tables are available. Conditional blocks are not supported (Excel templates do not support conditional section logic).

Field insertion — writes {FieldName} to the selected cell.

Loop table — writes a two-row block starting at the selected cell:

Row 1 (headers): FirstName  |  LastName  |  Email
Row 2 (tokens): {#Contacts}{FirstName} | {LastName} | {Email}{/Contacts}

Select the top-left cell of where you want the table before clicking Insert as Table.


PowerPoint / Slides

Field insertion is available. Loop tables and conditional blocks are not supported (PowerPoint templates do not support these constructs).

Field insertion — copies {FieldName} to the clipboard with a "Token copied — paste with Ctrl+V" confirmation. Click inside the target text box in PowerPoint, then paste.


Browsing objects and fields

The object picker loads all Salesforce objects accessible to the running user, sorted alphabetically. Use the search box to filter by name.

When you select an object, the component loads two lists:

  • Fields — all accessible, non-system fields on that object. Click Insert to place {FieldName} at the cursor.
  • Related Objects — child relationships (for loop tables) and parent lookups (for dot-notation tokens like {Account.Name}). Click Browse → to enter the related view.

In the related view, check the fields you want and click Insert as Table (or Insert as Table for Excel). The component returns to the browse view after inserting.

For parent lookups, the inserted token uses the relationship name + field name: {Owner.Name}, {Account.BillingCity}, etc.


Token reference

ScenarioToken syntax
Simple field{Name}, {AnnualRevenue}
Parent lookup field{Owner.Name}, {Account.BillingCity}
Child list (loop open){#Contacts}
Child list (loop close){/Contacts}
Conditional include{#IsActive}…{/IsActive}
Conditional exclude{^IsActive}…{/IsActive}
Equals condition{#Status == "Active"}…{/Status}

These tokens are identical to what you would type manually in a template file. The Template Builder is a convenience tool — all tokens it inserts are plain text and can be edited directly in Office afterward.


Relationship to the template object model

The Template Builder is a template authoring tool — it helps users write merge tokens into their Office files. It works alongside the Keelstone template object model but does not interact with those objects directly.

ObjectRole
Keelstone_Template__cIdentifies the template by a stable key and holds the template file in Salesforce Files. Referenced by KS: Generate Document at run time.
Keelstone_Template_Action__cJunction that scopes which action tiles appear in the taskpane for documents generated from a specific template.

A typical authoring workflow:

  1. Admin creates a Keelstone_Template__c record with a Template_Key__c
  2. Developer opens the template file in Office and opens the Template Builder taskpane to browse objects and insert tokens
  3. Admin configures Keelstone_Template_Action__c records to scope which actions appear when this template's documents are open
  4. Flow uses KS: Generate Document with templateKey to merge data and generate output

See Templates & Merge Variables for the full object reference.


Apex controller

The component uses TemplateBuilderController (in the managed package) to query the Salesforce schema:

MethodDescription
getObjects()Returns all queryable, accessible SObjects sorted by label. Cached.
getFields(objectName)Returns { fields, relatedObjects } for the given SObject. Both parent lookups and child relationships are included. Cached.

Both methods are @AuraEnabled(cacheable=true) and respect field-level security — users only see fields they have access to.