Create file

Overview

The Create File action is a powerful automation utility that bridges the gap between Flow data and Salesforce Files. It eliminates the need to manually navigate the complex relationship between ContentVersion, ContentDocument, and ContentDocumentLink.

circle-exclamation

Note: What this action is NOT

Key Capabilities

  • Dynamic Document Generation: Instantly turn user screen inputs, record fields, or data collections into downloadable documents.

  • Smart Linking: Automatically attaches the created file to any record (Opportunity, Case, Custom Object, etc.) via the Related Record ID, making it immediately visible in the record's "Files" related list.

  • Format Agnostic: Create anything from simple Log files (.txt) and Data exports (.csv) to complex Documents (.pdf) or Images, provided the source data is Base64 encoded.

  • Clean Output: Returns the new File ID immediately, allowing you to use the created file in subsequent Flow steps, such as sending it in an email or posting it to Chatter


Input Parameters

Parameter
Requirement
Description

Base64 Data

Required

The core content of your file, encoded in Base64 string format.

File Name

Required

The name of the file including the extension (e.g., Invoice_001.pdf).

Description

Optional

A brief summary of the file's content.

Related Record Id

Optional

The ID of the record (e.g., 006...) where the file should be attached.


How to Prepare Your Data (Visual Example)

The most common question is: "How do I get my Salesforce data into the Base64 Data field?" Because Salesforce stores files as binary data, you cannot simply plug a "Text" variable into this action. You must first encode your content.

1. Turning Text into a File (CSV/TXT)

If you want to create a file from record data or user input, follow this process:

  • Step A: Gather your content. Use a Loop and an Assignment (or a Text Template) to build your file's body. For a CSV, this would be a list of values separated by commas.

  • Step B: Encode to Base64. Since Flow doesn't have a native "Encode" button, you must use a helper.

    • Community Solution: Use a free Invocable Action (like Convert Text to Base64 from UnofficialSF).

    • Apex Solution: Use a simple one-line Apex method: EncodingUtil.base64Encode(Blob.valueOf(yourText)).

  • Step C: Map to Action. Pass the Output of that encoding step directly into the Base64 Data field of the Create File action.

2. The Logic Flow

Salesforce Data > Text Variable > Encoding Helper (Apex/Action) > Create file

circle-exclamation

Important


Example

Generating a CSV of Case Details

Use this example to learn how to turn record data into an attached file.

1

Gather your Data

Add a Get Records element to find the records you want to export.

  • Object: Case

  • Filter: AccountId equals recordId (The ID of the Account you are on).

2

Build the File Content

You need to turn those records into a "CSV string."

  • Create a Text Variable: Name it varCSVContent.

  • Loop: Iterate through your Case collection.

  • Assignment (Inside Loop): Add the Case data to your variable.

    Example: varCSVContent Add {!Loop_Case.CaseNumber} , {!Loop_Case.Subject} followed by a line break.

3

The "Base64" Transformation

The Create File action requires data in Base64 format. Since Flow doesn't do this natively, you have two options:

4

Configure the Create File Action

Map the output from Step 3 into the Create File parameters

Field
Value to Enter

Base64 Data

{!OutputFromStep3}

File Name

ClosedCases.csv (Don't forget the .csv extension!)

Related Record Id

{!recordId} (The ID of the Account where the file will be attached)

5

Result

When the Flow runs:

  1. It collects the Cases.

  2. It turns them into a text list.

  3. It encodes that list into Base64.

  4. Create File "re-hydrates" that code into a physical CSV file attached to your Account


Best Practices

  • Extensions Matter: Salesforce determines the file type by the extension you provide in the File Name field. Always include .pdf, .csv, or .txt.

  • Size Limits: Keep in mind that Apex actions have heap size limits. For extremely large files (multi-MB), ensure your Flow logic is optimized.

  • Privacy: If the file contains sensitive info, use the "Show Advanced Options" in the Flow Builder to set the visibility or sharing privacy of the created file.


Output Resources

Once the action runs, it returns:

  • fileId: The ID of the created ContentVersion.

  • fileName: The final name of the file.

  • fileType: The detected file format.

You can use these outputs later in your flow, for example, to post the file to a Chatter feed or display a "Download" link on a success screen.

Last updated

Was this helpful?