# Configure Document Generation On Your Record Page

## What You'll Build

In this tutorial, you'll add S-Docs Lightning Web Components to a Salesforce Lightning record page.

By the end, you'll have:

* A **Generate Documents (S-Docs)** component on a record page
* A **Documents (S-Docs)** component below it
* Optional email, refresh, versioning, and Live Edit features configured
* A tested record-page workflow for end users

## Prerequisites

Before starting, make sure you have:

* Complete [Create Your First Template](/quick-start/getting-started/create-your-first-template.md)
* Permission to edit Lightning record pages
* A test record for that object
* Access to Lightning App Builder
*
* The target object's API name, such as `Account`, `Opportunity`, or `Case`

If you plan to enable optional features, also confirm:

* You have an HTML email template ready for email actions
* Your template supports Live Edit if you want inline editing
* Your template is configured correctly for the output format you want to generate

{% hint style="info" %}
Documents generated from these components are saved as Salesforce Files and linked to the record.
{% endhint %}

{% stepper %}
{% step %}

#### Step 1: Pick the record page and test record

Choose the object where users will generate documents.

Then open one real record for that object.

Use this record later to test the page after configuration.
{% endstep %}

{% step %}

#### Step 2: Open Lightning App Builder

1. Open your test record.
2. Click **Setup**.
3. Go to **Object Manager**.
4. Open your target object.
5. Select **Lightning Record Pages**.
6. Open the page you want to edit.
7. Click **Edit**.

This opens **Lightning App Builder**.
{% endstep %}

{% step %}

#### Step 3: Add the Generate Documents component

1. In the component panel, search for **S-Docs**.
2. Drag **Generate Documents (S-Docs)** onto the page.
3. Place it where users should start the workflow.

A top section or left column usually works best.
{% endstep %}

{% step %}

#### Step 4: Configure Generate Documents (S-Docs)

Select the component and set the core properties.

Recommended starting configuration:

* **Title:** `Templates to Generate`
* **Object API Name:** your base object, such as `Account`
* **Template Name** or **Template IDs or Names:** choose the templates users should see
* **Notify User:** enabled
* **Open Preview:** enabled if users should review documents immediately

Use these options only when needed:

* **Allow Users to Select Templates** when users should choose from multiple templates
* **Reuse Template for Multiple Documents** when one template should generate several documents in one flow
  {% endstep %}

{% step %}

#### Step 5: Add the Documents component

1. Search for **S-Docs** again.
2. Drag **Documents (S-Docs)** onto the same page.
3. Place it directly below **Generate Documents (S-Docs)**.

This gives users a clean top-to-bottom workflow:

1. Generate documents
2. Review generated files
3. Email, refresh, edit, or inspect versions
   {% endstep %}

{% step %}

#### Step 6: Configure Documents (S-Docs)

Select **Documents (S-Docs)** and configure the features your users need.

Recommended starting configuration:

* **Title:** `Generated Documents`
* **Object API Name:** the same object used in the Generate Documents component

Optional configuration:

* Add an **Email Template** if users should send documents with a predefined message
* Enable **Automatically Open Email Editor** if users usually email right after generation
* Enable **Show Refresh** if users need to update document data after record changes
* Enable **Show Versions** if users need version history on refreshed or edited documents
  {% endstep %}

{% step %}

#### Step 7: Save and activate the page

1. Click **Save**.
2. Click **Activate** if the page is not already active.
3. Assign the page as needed for app, record type, or profile.

Then return to your test record.
{% endstep %}

{% step %}

#### Step 8: Test document generation

On the record page:

1. Find **Templates to Generate**.
2. Generate one document.
3. Confirm the document appears in **Generated Documents**.
4. Confirm the file is linked to the record.
5. If **Open Preview** is enabled, confirm the preview opens automatically.

Your base record-page setup is now complete.
{% endstep %}
{% endstepper %}

## Turn On Optional Features

Use the options below to expand the workflow.

### Send generated documents by email

Configure an HTML email template in the **Documents (S-Docs)** component when users send the same type of message often.

You can also enable **Automatically Open Email Editor** to open email right after generation.

For setup details, see [Sending Generated Documents via Email (S-Docs LWC)](https://github.com/kvantiem-sdocs/Quick-Start-Documentation/blob/main/automation-and-document-lifecycle/workflows/sending-generated-documents-via-email-s-docs-lwc.md).

### Refresh document data

Enable **Show Refresh** in the **Documents (S-Docs)** component when users need updated field values in an existing document.

Refresh updates the document content and creates a new version.

For details, see [Refresh Document Data Within the Documents (S-Docs LWC)](https://github.com/kvantiem-sdocs/Quick-Start-Documentation/blob/main/automation-and-document-lifecycle/workflows/refresh-document-data-within-the-documents-s-docs-lwc.md).

### Show document versions

Enable **Show Versions** when users need to review earlier document states.

This works best with **Refresh Data** and **Live Edit**.

For details, see [View Document Versions in the Documents LWC](https://github.com/kvantiem-sdocs/Quick-Start-Documentation/blob/main/automation-and-document-lifecycle/workflows/view-document-versions-in-the-documents-lwc.md).

### Enable Live Edit

Live Edit is controlled on the template.

To enable it:

1. Open the S-Docs template record.
2. Open the template editor.
3. Go to **Document Options**.
4. Under **Attachment & File Options**, enable **Allow Edit**.
5. Save the template.

After that, users can edit supported generated files from the **Documents (S-Docs)** component.

For details, see [Editing Generated Documents (Live Edit)](https://github.com/kvantiem-sdocs/Quick-Start-Documentation/blob/main/automation-and-document-lifecycle/workflows/editing-generated-documents-live-edit.md).

## Recommended Admin Setup

For most internal Lightning record pages, start with this pattern:

* **Generate Documents (S-Docs)** at the top
* **Documents (S-Docs)** directly below it
* **Notify User** enabled
* **Open Preview** enabled
* **Show Refresh** enabled when record data changes often
* **Show Versions** enabled when auditability matters
* A predefined email template when users send the same document type repeatedly

This keeps generation and post-generation actions in one place.

## Common Issues

<details>

<summary>Templates do not appear in the Generate Documents component</summary>

Check these items:

* The template is built for the same base object as the record page
* The template name or ID was entered correctly
* The user has access to the template
* The component's **Object API Name** matches the record page object

</details>

<details>

<summary>The document generates, but it does not appear in Generated Documents</summary>

Check these items:

* Both components use the same object configuration
* The document was created as a Salesforce File
* The page was saved and activated after configuration
* The record was refreshed after generation

</details>

<details>

<summary>Refresh or Versions options do not appear</summary>

Check these items:

* **Show Refresh** is enabled for refresh actions
* **Show Versions** is enabled for version history
* The page was saved and activated after changes

</details>

<details>

<summary>Edit does not appear for a generated document</summary>

Check these items:

* **Allow Edit** is enabled on the template
* The generated format supports Live Edit
* The document came from a template that has Live Edit enabled

</details>

<details>

<summary>DOCX generation does not work as expected</summary>

Check the template configuration.

For DOCX output, enable **New Microsoft Template Upload** on the template.

</details>

## What You've Built

You now have a Lightning record page where users can:

* Generate documents from S-Docs templates
* Review generated files without leaving the record
* Email documents
* Refresh document data
* View document versions
* Edit supported documents when Live Edit is enabled

## Related Guides

Use these pages when you want to expand the setup:

* [Add S-Docs to Record Pages](https://github.com/kvantiem-sdocs/Quick-Start-Documentation/blob/main/automation-and-document-lifecycle/workflows/README.md)
* [S-Docs LWC Reference](https://github.com/kvantiem-sdocs/Quick-Start-Documentation/blob/main/automation-and-document-lifecycle/workflows/s-docs-lwc-reference/README.md)
* [Sending Generated Documents via Email (S-Docs LWC)](https://github.com/kvantiem-sdocs/Quick-Start-Documentation/blob/main/automation-and-document-lifecycle/workflows/sending-generated-documents-via-email-s-docs-lwc.md)
* [Refresh Document Data Within the Documents (S-Docs LWC)](https://github.com/kvantiem-sdocs/Quick-Start-Documentation/blob/main/automation-and-document-lifecycle/workflows/refresh-document-data-within-the-documents-s-docs-lwc.md)
* [Editing Generated Documents (Live Edit)](https://github.com/kvantiem-sdocs/Quick-Start-Documentation/blob/main/automation-and-document-lifecycle/workflows/editing-generated-documents-live-edit.md)
* [View Document Versions in the Documents LWC](https://github.com/kvantiem-sdocs/Quick-Start-Documentation/blob/main/automation-and-document-lifecycle/workflows/view-document-versions-in-the-documents-lwc.md)

{% hint style="info" %}
The **S-Docs Usage Metrics** component is configured on a Home page, not a record page. Use that component separately when you want admin usage reporting.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.sdocs.com/quick-start/document-generation/add-s-docs-lightning-components-to-a-record-page.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
