> For the complete documentation index, see [llms.txt](https://docs.avonnicomponents.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avonnicomponents.com/flow/tutorials/components/csv-parser/import-a-file-stored-in-salesforce.md).

# Import a file stored in Salesforce

Import a CSV already attached to a record with File Value, or keep the uploaded file on the record with Save as Content Document.

The events team attaches the booth scanner export to the trade show's Campaign record the evening the show closes. The next morning, a sales coordinator opens the Campaign and imports the leads from that file, without downloading it and uploading it again.

The [CSV Parser](https://docs.avonnicomponents.com/flow/flow-components/csv-parser.md) covers both sides of this. With **File Value**, it reads a file already stored in Salesforce: the upload input disappears and the component only maps the columns. With **Save as Content Document**, it keeps a file the user uploads attached to the record, so the source of an import is always one click away.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FXpKxAMAFm2rtrgAW0wXW%2Fcsv-import-a-file-stored-in-salesforce-result.png?alt=media" alt="A CSV Parser on a flow screen without an upload control, showing Found 5 rows and seven CSV headers each mapped to a Lead field."><figcaption><p>A file already in Salesforce, mapped without an upload.</p></figcaption></figure>

## Before you start

* A screen flow that imports rows with the CSV Parser. [Import a CSV file in a screen flow](https://docs.avonnicomponents.com/flow/tutorials/components/csv-parser/101-tutorial.md) builds one.
* A Campaign with a CSV file in its **Files** related list, for part 1. Any object with Files works the same way.
* A way to launch the flow from the record, so it receives the record's Id: a screen flow action on the Campaign page layout, or the Flow component on the Campaign's Lightning record page.

## Part 1: import a file already attached to the record

{% stepper %}
{% step %}

### Receive the record Id

Create a text variable named `recordId` and check **Available for input**. When the flow runs from a Campaign, this variable holds the Campaign's Id.
{% endstep %}

{% step %}

### Find the file with Get Records

Before the screen, add a Get Records element named `Get_Booth_Scan_File`:

* Object: **Content Version**.
* Conditions: **First Publish Location ID** equals `{!recordId}`, **File Extension** equals `csv`, **Is Latest** equals `{!$GlobalConstant.True}`.
* Sort by **Created Date**, descending, and keep only the first record.

This returns the most recent CSV uploaded on that Campaign. Its **Content Document ID** is the value the CSV Parser needs.

{% hint style="info" %}
**First Publish Location ID** is the record a file was first uploaded to. For a file shared to the record later, query **Content Document Link** with **Linked Entity ID** equals `{!recordId}` and use its **Content Document ID** instead. That object cannot be filtered on the file type, so use it when the record holds only the one file.
{% endhint %}
{% endstep %}

{% step %}

### Point the CSV Parser at the file

Select the CSV Parser on the screen. In the right-hand panel:

* **File Value**: `{!Get_Booth_Scan_File.ContentDocumentId}`. Pick it from the resource list: the panel shows it as a pill labelled **Content Document ID**.
* **Object Name**, **Required Fields To Map** and **Default Mappings**: as for an upload. The file is mapped with the same rules.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FCoEO8pecmNubxRybm5JZ%2Fcsv-import-a-file-stored-in-salesforce-file-value.png?alt=media" alt="The CSV Parser settings panel in Flow Builder with Object Name set to Lead and File Value set to the Content Document ID of the Get Records result." width="320"><figcaption><p>File Value takes the Id of the file found by Get Records.</p></figcaption></figure>

**File Value** accepts three kinds of value:

| Value                                                  | Example                                           |
| ------------------------------------------------------ | ------------------------------------------------- |
| The Id of a file (Content Document or Content Version) | `{!Get_Booth_Scan_File.ContentDocumentId}`        |
| The CSV content itself, as text                        | A text variable or text template holding the rows |
| The CSV content encoded in Base64                      | The output of an action that returns a file body  |
| {% endstep %}                                          |                                                   |

{% step %}

### Decide how much the user sees

With **File Value** set, the upload input is hidden and the screen opens on the mapping, with sample data under each header. The user can still change a mapping before going on.

* Leave **Hide Mapping** off when the files vary, so the user can check the columns.
* Turn on **Hide Mapping** when every file has the same headers and your default mappings cover them. The screen then shows only the row count (and the preview, if **Show Preview** is on). [Pre-map CSV columns for a recurring import](https://docs.avonnicomponents.com/flow/tutorials/components/csv-parser/pre-map-csv-columns.md) explains what is still checked with the mapping hidden.
* Turn on **Show Row Count** either way.
  {% endstep %}

{% step %}

### Save and test

Add a Create Records on the CSV Parser's **Records** after the screen, or a [review screen](https://docs.avonnicomponents.com/flow/tutorials/components/csv-parser/review-rows-before-saving.md) first. Activate the flow, add it to the Campaign page, and open a Campaign with a CSV in its Files.

The screen opens without any upload input. The mapping lists the file's headers with three sample values each, and the row count of the file shows when **Show Row Count** is on.
{% endstep %}
{% endstepper %}

## Part 2: keep the uploaded file on the record

When the user uploads the file in the flow, the file itself is usually gone once the import is done. **Save as Content Document** stores it in Salesforce and can attach it to the Campaign, so anyone checking the import later finds the exact file it came from.

{% stepper %}
{% step %}

### Turn on Save as Content Document

Select the CSV Parser and click **Open Component Builder** at the top of the right-hand panel. In the **Edit CSV Parser Component** window, expand the **Save As Content Document** group of the **Properties** tab. This group is not in the right-hand panel.

* **Save as Content Document**: on.
* **Content Document Linked Entity Id**: `{!recordId}` (shown as a **Record Id** pill once picked). The file appears in the Campaign's **Files** related list. Leave it empty and the file is saved in the uploader's own files, attached to no record.

Click **Done** to close the window.

<figure><img src="https://27923732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1FUd4apB9YHgCEMUFbVb%2Fuploads%2FCUK0oWIt6eGnEk6I8yDC%2Fcsv-import-a-file-stored-in-salesforce-save-as-content-document.png?alt=media" alt="The Save As Content Document group of the CSV Parser Component Builder, with Save as Content Document turned on and Content Document Linked Entity Id set to the recordId variable." width="320"><figcaption><p>The uploaded file is saved and attached to the record.</p></figcaption></figure>
{% endstep %}

{% step %}

### Know when the file is saved

The CSV Parser saves the file the moment the user picks it, before the rows are mapped and before Next:

* A "Your content document has been created." toast confirms it.
* The file stays even if the mapping fails or the user leaves the flow.
* Each upload creates a new file. A user who picks the wrong file and then the right one leaves two files on the record.

**File Value** and **Save as Content Document** do not combine: only a file the user uploads is saved.
{% endstep %}

{% step %}

### Use the Content Document Id output

Once the file is saved, the CSV Parser's **Content Document Id** output holds the new file's Id. Use it after the screen, for example to write it to a field on an import log record, or to link the same file to a second record with a Create Records on **Content Document Link**.
{% endstep %}

{% step %}

### Save and test

Run the flow from a Campaign and upload a CSV. The success toast appears as soon as the file is picked. Open the Campaign: the file is in its **Files** related list, whether or not you finished the flow.
{% endstep %}
{% endstepper %}

## Troubleshooting

<details>

<summary>"Could not parse the file value provided."</summary>

The CSV Parser could not turn **File Value** into CSV content. Check, in this order:

* The Get Records found nothing, so **File Value** is empty or wrong. Debug the flow and look at `Get_Booth_Scan_File`.
* The running user cannot see the file. The file is read with the user's own access, so a file on a record they cannot open is treated as missing.
* The content has no comma at all. The CSV Parser recognizes CSV text by its commas, so a file separated only by semicolons is rejected here. See [Fix encoding and delimiter issues](https://docs.avonnicomponents.com/flow/tutorials/components/csv-parser/fix-encoding-and-delimiter-issues.md).

</details>

<details>

<summary>Accented characters look wrong in a stored file</summary>

A file read through **File Value** is always decoded as UTF-8, whatever **Encoding** says. Save the file as CSV UTF-8 before attaching it. [Fix encoding and delimiter issues](https://docs.avonnicomponents.com/flow/tutorials/components/csv-parser/fix-encoding-and-delimiter-issues.md) explains how to recognize the problem.

</details>

<details>

<summary>The flow imported the wrong file</summary>

The record holds several CSV files and the Get Records returned another one. Keep the sort on **Created Date** descending with only the first record, or add a condition on **Title**.

</details>

<details>

<summary>An error toast appears on upload with Save as Content Document on</summary>

The running user lacks a permission. "You do not have permission to upload files." means they cannot create files. "You do not have permission to link files." or "You do not have permission to link this file." means they cannot attach the file to the record in **Content Document Linked Entity Id**.

</details>

<details>

<summary>The Content Document Id output is empty</summary>

**Save as Content Document** is off, the save failed (look for an error toast), or the rows came from **File Value**, which saves nothing.

</details>

## Related tutorials

* [Review rows before saving](https://docs.avonnicomponents.com/flow/tutorials/components/csv-parser/review-rows-before-saving.md): show the stored file's rows in an editable table before creating anything.
* [Pre-map CSV columns for a recurring import](https://docs.avonnicomponents.com/flow/tutorials/components/csv-parser/pre-map-csv-columns.md): a stored file often comes from the same export every time, which is when default mappings pay off.
* [Fix encoding and delimiter issues](https://docs.avonnicomponents.com/flow/tutorials/components/csv-parser/fix-encoding-and-delimiter-issues.md): when a file is read but the columns or characters come out wrong.
* [CSV Parser](https://docs.avonnicomponents.com/flow/flow-components/csv-parser.md): every setting of the component, in one place.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.avonnicomponents.com/flow/tutorials/components/csv-parser/import-a-file-stored-in-salesforce.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
