You can now upload CSV data and turn it into Salesforce records with just a couple of Flow elements

This action is based on original work by Narender Singh, plus nice new improvements by Hijlko and Suraj Pillai.

(Interested in exporting records to CSV? Check that out here)

Advertisement

Here’s all that’s needed to take a typical CSV file and turn it into a collection of Accounts that you can save or modify.

The work is done by the ConvertCSVToRecords invocable action. It takes as input one or more Content Document ID’s. This is the main way you refer to files that have been uploaded to Salesforce. In the example above, we use a File Upload screen component to upload a CSV file. (see Considerations: Uploading Files, below for more information). It outputs a Content Document ID which is then fed into the new action.

The action takes advantage of Flow support for generic SObjects in invocable actions. This is the same enhancement that enables Collection Actions. Here, at design time, I specify both the name of the object type “Account” and you select Account as the expect output from the action:

Considerations: Uploading Files

The video in this post shows an example that uses the out-of-the-box File Upload component. It requires a recordId to be provided, and it stores uploaded files ‘on’ that recordId. This makes a lot of sense when you’re trying to upload Account or Contact-related files, but doesn’t make a lot of sense here where we’re just trying to import data. As the video here shows, I actually created a separate object just to hold these values.The import process doesn’t actually make use of this related record. This is all a little annoying. Fortunately, since that video was recorded members of the Flow community have created a replacement extension called File Upload Improved, which doesn’t require a recordId. We recommend that for use with CSV Uploading.

CSV File Considerations

The first row of your file should consist of the field names you want to upload. Make sure you use apinames, include “__c” for your custom fields, and pay attention to the required fields for the records you’re uploading. Note: there should be no NULL values in the last column of CSV.

As of Version 1.2, the following things are supported:

Row Data Support

  • Text and Date fields
  • Embedded commas
  • Rows/File beginning and ending with quotes
  • Newline characters within columns
  • Null columns at the end of a row
  • Supports the CSV spec definition of double quotes, which is represented by consecutive double quotes ("") within a column enclosed in double quotes:

Column Header Support

Column Headers should be in the first row of the file and should be api field names:

Column Headers that are not already field API names will be converted to API Name format

Examples:
Purchase Amount => Purchase_Amount__c
Nuts & Bolts => Nuts_Bolts__c

Support for Non-US Separators

Contributor Hijlko added this useful improvement. With it, you can import CSV files containing values that use non-comma separators like semicolons. Standard US csv uses a comma as a field separator while most European csv’s use a semicolon as a field seperator.The code can now import muli region CSV files
Numbers/currency like 1,2345.56 (US) and 1.234,56 (EU) are converted to 1234.56

You can now set the following:

  • Field Separator
  • Thousand Separator
  • Decimal Separator
  • Currency Symbol

If these inputs are left empty, the existing default values will be used.

Support for Non-US Dates

Date values in the formats YYYY-MM-DD and DD-MM-YYYY (or with non-hyphen separators like YYYY/MM/DD and DD/MM/YYYY) are now automatically converted to YYYY-MM-DD, which is the Salesforce standard.

Inputs

Object API Name

Required. Tells Flow what to convert your data into. Example “Account”. Make sure your CSV file has all the required fields

contentDocumentId

A single Content Document record ID string

contentDocumentIdList

Collection of Strings.

isTrim

Set isTrim to true to have any leading or trailing spaces removed.

Output

A collection of Records

Install Package

Version 1.3 Unlocked 9/3/21 Support for Non-US Separators,Support for Non-US Dates ,Additional Robustness in Handling Non-Alphabetical Characters

Old Versions

View Source

Please click here to read the original article as posted on UnofficialSF.

We source the web to bring you best Salesforce articles for our reader’s convenience. If you want to have this article removed, please follow guidelines at Digital Millennium Copyright Act (DMCA)..