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

Example
Generating a CSV of Case Details
Use this example to learn how to turn record data into an attached file.
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:
varCSVContentAdd{!Loop_Case.CaseNumber} , {!Loop_Case.Subject}followed by a line break.
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));
Configure the Create File Action
Map the output from Step 3 into the Create File parameters
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)

Result
When the Flow runs:
It collects the Cases.
It turns them into a text list.
It encodes that list into Base64.
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. Images are the one exception: the action accepts a full data URI (data:image/png;base64,...) as Base64 Data, and adds the.png,.jpg,.gifor.webpextension 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
ContentDocumentID, which starts with069).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?
