For the complete documentation index, see llms.txt. This page is also available as Markdown.

Getting Started: Automate Document Generation

Build a Salesforce Screen Flow that generates a PDF document with S-Docs.

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

Generated files usually appear in Files. Some orgs also use Documents & Attachments.

1

Step 1: Create the Screen Flow

Start with a basic Screen Flow.

  1. Go to SetupFlows

  2. Click New Flow

  3. Choose Screen Flow

  4. Click Create

What you completed:

  • Created the flow container

  • Started a flow you can place on a Lightning record page

2

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

What you completed:

  • Created the standard record-page flow variable

  • Gave the flow a base record to generate against

3

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

What you completed:

  • Added the invocable S-Docs action to the flow

  • Created the step that performs document generation

4

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

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

5

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:

  1. Click Done

6

Step 6: Name the flow

Give the flow a clear, fixed name.

  1. Click Save

  2. Enter Generate Opportunity PDF

  3. Click Save

7

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

8

Step 8: Create the flow action

Create the record-page action that launches the flow.

  1. Go to SetupObject 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

What you completed:

  • Created a reusable flow action for Opportunity

  • Prepared the flow for record-page placement

9

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 ManagerOpportunity

  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 GearEdit 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

10

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

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

Common Issues and Solutions

I cannot find the Generate Document action

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

The flow action does not appear on the record page

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

The flow works in debug, but not from the record page

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

The flow finishes, but no document is created

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

I do not see the generated file on the record

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

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

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

Last updated

Was this helpful?