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

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.

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

In Flow Builder, add an Action element and pick Create File under the Avonni category. The action takes four inputs:

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

Flow Builder canvas showing Start, Get Cases, a For Each Case loop with an Add Case to CSV assignment, then Encode to Base64, Create File, a File Created screen and End
The example below, as a flow: the cases are gathered, written into a text variable one line at a time, encoded, then handed to Create File.

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:

  • Option A (Recommended): Use a free community action like UnofficialSF's "Convert Text to Base64".

  • Option B (Custom): Create a tiny Apex Action with one line of code:

    return EncodingUtil.base64Encode(Blob.valueOf(inputText));

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)

The Create File action open in Flow Builder, with Base64 Data set to the output of the Encode to Base64 action, File Name set to ClosedCases.csv, Description empty and Related Record Id set to recordId
The Create File action in Flow Builder with the example's values. Base64 Data takes the output of the encoding step, and Related Record Id the account the flow runs on.
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

The Notes & Attachments related list of an account, showing ClosedCases.csv, 134 bytes, csv
The result: ClosedCases.csv attached to the account, here in its Notes & Attachments related list. The Files related list shows the same file where the page layout carries it.

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. Images are the one exception: the action accepts a full data URI (data:image/png;base64,...) as Base64 Data, and adds the .png, .jpg, .gif or .webp extension itself when the file name lacks it.

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

  • Sharing: With a Related Record Id, the file is shared with everyone who can see that record. Without one, it is created in the running user's files and stays visible to that user only until it is shared. The action has no visibility or sharing setting of its own.


Output Resources

Once the action runs, it returns:

  • fileId: The ID of the created file (its ContentDocument ID, which starts with 069).

  • 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?