Importing Accounts with Binary Attachments

In this tutorial, we will show how to import binary files together with a CSV file. Suppose we need to import a CSV file with Salesforce accounts and attachments for these accounts. Attachment data are stored as a field of the base64 type. It would be impractical to convert all the attachment files to base64 values and put them inside a CSV file. Instead we will import them as is — as a collection of binary files.

To import a collection of binary files together with a CSV file, you need to zip them and add information on which file corresponds to which data row to the CSV file. The simplest way would be to add a column, containing a file name, to the CSV file.

In our case we have two choices. If we import a fixed number of attachments for each imported account, we may add all the necessary columns for attachments to the CSV file, containing the accounts. However, if the number of attachments for a single account can be different, you will need to create a separate CSV file with information about attachments. In the latter case you will need to specify an account to import an attachment for.

To avoid using Salesforce IDs in the CSV file, we consider that imported account names are unique and use account names to specify the attachment owners. We will need the following columns in the Attachments.csv file:

  • AccountName — will be used to specify the account owner using Relation mapping
  • ContentType — this column determines the type of the imported attachment file (can be omitted if all the imported attachments have the same type)
  • FileName — name of the corresponding attachment file in the zip archive.

When importing a single CSV file, containing information on accounts and attachments, you will need to add columns, specifying the names of the files to import as attachments. The number of these columns must be the same as the number of attachments per account. In case the attachment file types are different, you will also need the same number of columns, specifying the content type.

This tutorial demonstrates both scenarios: with a single CSV file and with separate CSV files.

Creating Connection

Regardless of the way you want to use to specify parent accounts for contacts, first you need to create a connection to the target Salesforce database, if you haven’t created it before. To create a connection to Salesforce, perform the following steps:

  1. Click +NEW in the top menu.
  2. Click the Connection button in the menu on the left.
  3. In the opened Select Connector page, select Salesforce. To quickly find it, you can either use the Type to filter box or filter connectors by categories using the All list (for Salesforce, select the CRM category).
  4. The default name of a new connection is Untitled. Just click it to rename the connection, for example, to Salesforce1.
  5. From the Environment drop-down list select the Salesforce environment type to import data to. Since this is just a sample walkthrough, the Sandbox environment is recommended.
  6. From the Authentication drop-down list select the authentication method for connecting to Salesforce. If you don’t mind storing your Salesforce credentials on our Skyvia server, select User Name & Password. If you prefer not to store your credentials, select OAuth 2.0.

    Connection Editor window

  7. If you have selected User Name & Password, on the previous step, specify your Salesforce account e-mail, password, and security token. Otherwise, if you have selected OAuth 2.0 authentication, click the Sign In with Salesforce button and log in via the Salesforce website on the opened page. The result OAuth token will be stored in the connection data. Your Salesforce credentials will not be stored on our website.

    Log In window

  8. Click the Create Connection button to create the connection.

    Connection Editor window 2

Importing Accounts and Attachments stored in Single CSV File

  1. Click +NEW in the top menu.
  2. In the Integration column, click Import. The import package details page will open.
  3. Rename your package by clicking and editing the package name. The default package name is Untitled. Please note, if you omit this step, the package name will remain Untitled in the list of created packages.
  4. Under Target, in the Connection list, click Select target and select Salesforce1 in the drop-down list.

    Target Connection

  5. Click the Add new link to open the Task Editor.
  6. Click browse and select the CSV file with Accounts data to import.

    Source CSV

  7. Select the Add zip with binary data checkbox.

    Add zip with binary data

  8. Click browse and select the zip file with attachments to import.
  9. If necessary, set the CSV Options.

    CSV Options

  10. Click the Next step button in the bottom of the dialog box to switch to the next editor page. You can also switch between the editor pages by clicking the corresponding icons: Source Definition, Target Definition, and Mapping Definition.
  11. Select Account in the Target list.

    Target List

  12. Click +Related near Account and in the new drop-down list select Attachment. If you import several attachments per account, perform this action the number of times equal to the number of attachments per account. Note that you should click the same +Related near Account, not the buttons near added Attachments.

    Related button

  13. Click the Next step button in the bottom of the dialog box to switch to the next editor page or click the Previous step button to return to the previous page.
  14. Map the Account fields to the corresponding source columns.
  15. To map Attachment object fields, click the target table name (Account) and select Account.Attachment in the drop-down list.
  16. Map the Name field to the FileName column.
  17. Click the Body field and then, in the Column drop-down list, select Zip File.
  18. Enter “FileName” to the box (without quotes).

    Body field

  19. If you have all the attachments of the same type and haven’t added the ContentType column to the CSV file, let’s specify the attachment type as an expression.
  20. Click the ContentType field and then, in the Column drop-down list, select Constant.
  21. In our example all the attachments are PNG images, so enter “image/png” to the box (without quotes).

    ContentType field

  22. If you have specified content type in a CSV file column, map the ContentType field to this column instead of using the expression.
  23. If you are importing several attachments per account, repeat the steps 15 - 22, each time selecting the next Account.Attachment entry in the tables mapping drop-down list and specifying the corresponding column for the Body field until all the imported attachments are mapped.

    Mapping drop-down list

  24. Click the Save button to save the task.
  25. Click the Create button to create the package.

Importing Accounts and Attachments stored in Separate CSV Files

In this case we will create two import tasks for importing Accounts and Attachments respectively. Note that in this scenario you can import an arbitrary number of attachments per account.

Creating Package

  1. Click +NEW in the top menu.
  2. In the Integration column, click Import. The import package details page will open.
  3. Rename your package by clicking and editing the package name. The default package name is Untitled. Please note, if you omit this step, the package name will remain Untitled in the list of created packages.
  4. Under Target, in the Connection list, click Select target and select Salesforce connection from the drop-down list. You can use the Type to filter box to quickly find the necessary connection.

    Target Connection

Importing Accounts

  1. Click the Add new link to open the Task Editor.
  2. Click browse and select the CSV file with Accounts data to import.

    Source CSV

  3. If necessary, set the CSV Options.

    CSV Options

  4. Click the Next step button in the bottom of the dialog box to switch to the next editor page. You can also switch between the editor pages by clicking the corresponding icons: Source Definition, Target Definition, and Mapping Definition.
  5. Select Account in the Target list and then click Next step to switch to the next editor page or click the Previous step button to return to the previous page.
  6. Map the Account fields to the corresponding source columns.
  7. Click the Save button to save the task.

Importing Attachments

  1. Click the Add new link to open the Task Editor.
  2. Click browse and select the CSV file with Attachments data to import.

    Source CSV

  3. Select the Add zip with binary data checkbox.

    Add zip with binary data

  4. Click browse and select the zip file with attachments to import.
  5. If necessary, set the CSV Options.

    CSV Options

  6. Click the Next step button in the bottom of the dialog box to switch to the next editor page. You can also switch between the editor pages by clicking the corresponding icons: Source Definition, Target Definition, and Mapping Definition.
  7. In the Target list, select Attachment and then click Next step to switch to the next editor page or click the Previous step button to return to the previous page.
  8. Click the ParentID field and then, in the Column drop-down list, select Relation.
  9. Under the Referenced Object drop-down list, select the Reference itself checkbox. It automatically selects Accounts.csv.
  10. In the Column drop-down list, select Name.
  11. In the Referenced Column drop-down list, select Name.

    Referenced column

  12. Repeat the steps 8-11 for the OwnerId field.
  13. Map the Name field to the FileName column.
  14. Click the Body field and then, in the Column drop-down list, select Zip File.
  15. Enter “FileName” to the box (without quotes).

    Body field

  16. If you have all the attachments of the same type and haven’t added the ContentType column to the CSV file, let’s specify the attachment type as a constant.
  17. Click the ContentType field and then, in the Column drop-down list, select Constant.
  18. In our example all the attachments are PNG images, so enter “image/png” to the box (without quotes).

    ContentType field

  19. If you have specified content type in a CSV file column, map the ContentType field to this column instead of using the expression.
  20. Click the Save button to save the task.
  21. Click the Create button to create the package.