From Andy Haas: A high-volume Convert CSV To Records screen component

If you want to import a CSV file, you can use this existing invocable action. It has a good feature set, but there are some limits on the file size that can be imported that stem from backend Salesforce limits. Andy Haas has provide a complementary Flow Screen Component that also allows CSV imports. This version processes files on your local computer, and can work with larger files. This component will automatically navigate to the next screen when the parsing has been completed.

Use Cases

The CFO at a large company has come to you with a request to allow end users to import a CSV file from their merchant companies each month. He doesn’t want to have to call you each month or learn another platform to import these records. He tells you that they partner with many different merchant processor companies and the files will stay the same each month; he wants the process to be as simple as possible for the end users. You ask him for the CSV files to create an object and fields corresponding to the file.

You sit down, open the CSV file the CFO sent to you, and create the object with the appropriate fields. You then open up a new Screenflow, drag the Convert CSV to Records – LWC Version to the screen, and set up the component’s configuration. 

After you have set up the component, you test drive it out and see how quick and simple this will be. You schedule a meeting with the CFO and show him the progress; he is amazed at how well this works.

In the above use case, we talked about utilizing the component for a monthly import that the CFO has to do; this can also be used with a one-time import or a multitude of different use cases where the user is importing a file. If a user is not initiating the import, the existing invocable action will be the correct action to use. 

Setup

Add the Convert CSV to Records – LWC to the screen.

Inputs

The inputs consist of 4 required inputs and a large list of optional advanced features. The underlying PapaParse library provides advanced features and is documented in the PapaParse documentation.

Input NameDefault ValueDescription
API NameThe name of the component.
Input ObjectThis is used to get the field definition.
File Import LabelThe label for the file input field.
Auto Navigate NextIf true, the flow will automatically navigate to the next screen after the component has been initialized.
Delimeter,The delimiting character. Leave blank to auto-detect from a list of most common delimiters, or any values passed in through delimitersToGuess.
New LineThe newline sequence. Leave blank to auto-detect. It must be one of \r, \n, or \r\n.
Quote Character"The character used to quote fields. The quoting of all fields is not mandatory. Any field which is not quoted will be correctly read.
Escape Character"The character used to escape the quote character within a field. 
Transform HeaderA function to apply on each header. The function receives the header as its first argument and the index as second.
Dynamic TypingIf true, numeric and boolean data will be converted to their type instead of remaining strings.
EncodingUTF-8The encoding to use when opening local files. If specified, it must be a value supported by the FileReader API.
CommentsA string that indicates a comment (for example, # or //). When Papa encounters a line starting with this string, it will skip the line.
Fast ModeFast mode speeds up parsing significantly for large inputs. However, it only works when the input has no quoted fields. Fast mode will automatically be enabled if no ” characters appear in the input.
TransformA function to apply on each value. The function receives the value as its first argument and the column number or header name when enabled as its second argument. The return value of the function will replace the value it received. The transform function is applied before dynamicTyping.
Delimiters to GuessAn array of delimiters to guess from if the delimiter option is not set.

For further details on the input values, please visit the PapaParse Documentation.

Please note that the following PapaParse inputs will be set within the component and can not be changed. Keep this in mind if any conflicting inputs will error out.

PapaParse NameValueDescription
HeaderTRUEThe first row of parsed data will be interpreted as field names.
Skip Empty LinesTRUELines that are completely empty (those which evaluate to an empty string) will be skipped.

Column Headers

The header columns are compared against the objects fields, and if the header column is a custom field and the header isn’t labeled that way, the component will rename the header and assign the custom field.

Example

Input Object: Account

CSV Headers: Name, Description, Active

The component will convert the above CSV Headers to the following:

Name, Description, Active__c

Outputs

Output NameAPI NameDescription
Parsed ResultsoutputValueAn sObject of the parsed results.
Is ErrorisErrorWill be marked true if an error has occurred when attempting to parse the CSV file.
Error MessageerrorMessageWill output the value of the error that had occurred.

Implementations

Implementing this component can be as simple as creating records right after parsing like so:

Or you can be more complex with loops and filters as the output is an SObject allowing manipulation of the imported data.

With Spring ‘23 and the added ability for reactive screens, you can use this component to preview the data uploaded before creating records.

Install Link

Production/Dev

V1.0.1 1/14/23 Production Sandbox Fixed setting the selected object in CPE

Old Versions

V1.0 12/29/22 Production Sandbox 1st version hosted on FlowComponents

Source

View Source