> For the complete documentation index, see [llms.txt](https://help.sdocs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.sdocs.com/quick-start/document-generation/getting-started-automate-document-generation.md).

# Getting Started: Automate Document Generation

## Objectives

In this tutorial, you will build a simple record-page flow that generates one PDF from an `Opportunity`.

#### Learn to:

* Create a Salesforce Screen Flow for S-Docs generation
* Pass the current `Opportunity` record into the flow with `recordId`
* Configure the **Generate Document** Apex action
* Add a launch action to the `Opportunity` record page
* Test PDF generation from a real record

#### By the end, you will have:

* One Screen Flow that generates the document
* One S-Docs generation action tied to a fixed template
* One confirmation screen after generation
* One generated PDF saved back to the record

***Estimated time:** 15 minutes*

## Prerequisites

Before you start, make sure you have:

* Permission to create, save, and activate Salesforce Flows
* Permission to edit Lightning record pages
* Complete [Create Your First Template](/quick-start/getting-started/create-your-first-template.md)

{% hint style="info" %}
Generated files usually appear in **Files**. Some orgs also use **Documents & Attachments**.
{% endhint %}

{% stepper %}
{% step %}

#### Step 1: Create the Screen Flow

Start with a basic Screen Flow.

1. Go to **Setup** → **Flows**
2. Click **New Flow**
3. Choose **Screen Flow**
4. Click **Create**

<figure><img src="/files/3WRGQheeywusZPNr8yag" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/nj8q3PQQrKpbNuWBgv6h" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/lVgjbadnbT7i0wBGmP6S" alt=""><figcaption></figcaption></figure>

#### What you completed:

* Created the flow container
* Started a flow you can place on a Lightning record page
  {% endstep %}

{% step %}

#### Step 2: Create the `recordId` input variable

The flow needs the current `Opportunity` ID from the record page.

1. Open the **Manager** tab in the Toolbox in Flow Builder
2. Click **New Resource**
3. Set **Resource Type** to **Variable**
4. Set **API Name** to `recordId`
5. Set **Data Type** to **Text**
6. Enable **Available for input**
7. Click **Done**

<figure><img src="/files/6MLDQAJrWbIQnKskRw6A" alt=""><figcaption></figcaption></figure>

#### What you completed:

* Created the standard record-page flow variable
* Gave the flow a base record to generate against
  {% endstep %}

{% step %}

#### Step 3: Add the Generate Document action

Now add the S-Docs action that creates the document.

1. Click the **+** after **Start**
2. Choose **Action**
3. Search for `Generate Document`
4. Select `apex-SDOC__GenerateDocumentInvocable`
5. Set **Label** to `Generate Document`
6. Set **API Name** to `Generate_Document`

<figure><img src="/files/8SRLGIMyIY76COgeEPab" alt="" width="313"><figcaption></figcaption></figure>

#### What you completed:

* Added the invocable S-Docs action to the flow
* Created the step that performs document generation
  {% endstep %}

{% step %}

#### Step 4: Configure the action inputs

Map the flow to the record and template.

In **Set Input Values**:

1. Set **Base Record ID** to `{!recordId}`
2. Enter the exact S-Docs template name in the template input field
3. Leave other values at their defaults unless your use case requires them
4. Click **Done**

<figure><img src="/files/jX8bOjcjTBlDlhyiJJMo" alt="" width="375"><figcaption></figcaption></figure>

Use the exact template name from the S-Docs template record.

#### What you completed:

* Connected the action to the current `Opportunity`
* Fixed the flow to one S-Docs template for repeatable output
  {% endstep %}

{% step %}

#### Step 5: Add the confirmation screen

Add a simple end screen after generation.

1. Click the **+** after the S-Docs action
2. Choose **Screen**
3. Set **Label** to `Document Created`
4. Set **API Name** to `Document_Created`
5. Add a **Display Text** component
6. Use a short message such as:

{% code title="Confirmation message" %}

```
Document generated successfully. 
Check Files or Documents & Attachments to view or download it.
```

{% endcode %}

7. Click **Done**
   {% endstep %}

{% step %}

#### Step 6: Name the flow

Give the flow a clear, fixed name.

1. Click **Save**
2. Enter `Generate Opportunity PDF`
3. Click **Save**
   {% endstep %}

{% step %}

#### Step 7: Activate the flow

Make the flow available for use on a record page.

1. Click **Activate**

After activation, the flow is ready to place on the record page
{% endstep %}

{% step %}

#### Step 8: Create the flow action

Create the record-page action that launches the flow.

1. Go to **Setup** → **Object Manager**
2. Select **Opportunity**
3. Click **Buttons, Links, and Actions**
4. Click **New Action**
5. Set **Action Type** to **Flow**
6. Select your flow from the **Flow** dropdown
7. Enter a clear **Label**, such as `Generate Document`
8. Click **Save**

<figure><img src="/files/sXhT7gcVJlTWyWH4o9UU" alt=""><figcaption></figcaption></figure>

#### What you completed:

* Created a reusable flow action for `Opportunity`
* Prepared the flow for record-page placement
  {% endstep %}

{% step %}

#### Step 9: Add the action to the Opportunity record page

Place the action where users can launch it.

If your org uses traditional **Page Layouts (common practice)**:

1. Go back to **Object Manager** → **Opportunity**
2. Open **Page Layouts**
3. Select the layout you want to edit
4. Click **Mobile & Lightning Actions**
5. Drag your new flow action into **Salesforce Mobile and Lightning Experience Actions**
6. Click **Save**

If your org uses **Dynamic Actions (Modern, simple)**:

1. Open a real `Opportunity` record
2. Click **Gear** → **Edit Page**
3. Click the **Highlights Panel**
4. Click **Add Action** in the properties panel
5. Select your new flow action
6. Click **Done**
7. Click **Save**
8. Click **Activate**

#### What you completed:

* Added a launch point on the record page
* Made the flow available to end users in the right context
  {% endstep %}

{% step %}

#### Step 10: Test document generation

Run the flow from a real record.

1. Return to the test `Opportunity` record
2. Click the new flow action on the record page
3. Let the flow finish
4. Check the record for the generated file

<figure><img src="/files/HcpZE6HnLqjGYqYEdrqT" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/Qmsfi4nU3uPLH9V8mqqK" alt=""><figcaption></figcaption></figure>

#### Verify results:

* The flow completes without an error
* The document is generated from the expected template
* The PDF is linked to the same `Opportunity`
* The file appears in **Files** or **Documents & Attachments**
  {% endstep %}
  {% endstepper %}

## Common Issues and Solutions

<details>

<summary>I cannot find the Generate Document action</summary>

Check these items:

* S-Docs is installed in the org
* Your user can access S-Docs Apex actions
* You searched for `Generate Document` inside **Action**

</details>

<details>

<summary>The flow action does not appear on the record page</summary>

Check these items:

* The flow is **Active**
* You created the action with **Action Type** set to **Flow**
* The action was added to **Dynamic Actions** or the page layout
* The record page or page layout was saved after the change

</details>

<details>

<summary>The flow works in debug, but not from the record page</summary>

Check these items:

* The flow includes a text variable named `recordId`
* `recordId` is marked **Available for input**
* The record page launches the flow from a record context
* The running user can access the flow and S-Docs action

</details>

<details>

<summary>The flow finishes, but no document is created</summary>

Check these items:

* The template name matches the S-Docs template exactly
* The template is related to `Opportunity`
* The running user can access the template
* The `Opportunity` record has the data the template expects

</details>

<details>

<summary>I do not see the generated file on the record</summary>

Check these items:

* Refresh the record page
* Check **Files**
* Check **Documents & Attachments** if your org still uses it
* Confirm the document generated against the same record you launched from

</details>

## What You've Learned

✅ Created a Screen Flow for S-Docs generation\
✅ Passed the current record into the flow with `recordId`\
✅ Configured the **Generate Document** Apex action\
✅ Added the flow action to the `Opportunity` record page\
✅ Tested PDF generation from a live record

## Next Steps

* Use [Create Your First Template](/quick-start/getting-started/create-your-first-template.md) to build the template used by the flow.
* Use [Configure Document Generation For Your Record Page](/quick-start/document-generation/add-s-docs-lightning-components-to-a-record-page.md) to add a fuller record-page generation workflow.

## Practice Exercise

Build a second version of this flow for another template.

1. Copy the flow.
2. Change the template input to a second `Opportunity` template.
3. Create a second flow action for the copied flow.
4. Add the new action to a test record page.
5. Generate a document from a real record.
6. Confirm the second file appears on the same record.

Bonus challenges:

* Create one version for `Account`
* Add clearer confirmation text after generation
* Test the flow with two different records and compare the output


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://help.sdocs.com/quick-start/document-generation/getting-started-automate-document-generation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
