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 is 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 - determines the type of the imported attachment file (can be omitted if all the imported attachments have the same type)
FileName - the 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.

 

ExpandedToggleIcon        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 Connections in the menu on the left side of the page to switch to the Connections page.
2.On the Connections page click the New button.
3.In the opened pane click Salesforce.
4.Specify the connection Name, for example, 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.
 
salesforce-connection-oauth
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 Log In with Salesforce button and login 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.
 
Login-to-Salesforce
8.Click the Save button to save the connection.
 
salesforce-connection-oauth-filled

ExpandedToggleIcon        Importing Accounts and Attachments, stored in Single CSV File

1.Click Integration in the menu on the left side of the page.
2.Click the New button in the top right corner of the page.
3.Click Import.
4.In the Target header click Select and select Salesforce in the drop-down list.
5.Select Salesforce1 in the Target Connection drop-down list.
 
target-connection-selection
6.Click the + Add task to open the Import Wizard.
7.Click browse and select the CSV file with Accounts data to import.
 
upload-csv-file
8.Click the Add zip with binary data link.
 
link-binary-data
9.Click browse and select the zip file with attachments to import.
 
uploaded-files-with-zip
10. If necessary, set the CSV Options.
 
csv-options
11. Click the Next button in the bottom of the dialog box. You can also switch between the Import Wizard pages by clicking the corresponding icons in the wizard header and return to previous wizard page by clicking the Previous button.
12. Select Account in the Target list.
 
multiple-objects-account
13. Click Add 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 Add Related near Account, not the buttons near added Attachments.
14. Click the Next button in the bottom of the dialog box. You can also switch between the Import Wizard pages by clicking the corresponding icons in the wizard header and return to previous wizard page by clicking the Previous button.
15. Map the Account fields to the corresponding source columns.
16. To map Attachment object fields, select Account.Attachment in the Tables Mapping drop-down list.
17. Map the Name field to the FileName column.
18. Click the Body field and then, in the Column drop-down list, select Zip File.
 
zip-file-mapping
19. Enter "FileName" to the box (without quotes).
20. 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.
21. Click the ContentType field and then, in the Column drop-down list, select Constant.
 
content-type-expression
22. In our example all the attachments are PNG images, so enter "image/png" to the box (without quotes).
23. If you have specified content type in a CSV file column, map the ContentType field to this column instead of using the expression.
24. If you are importing several attachments per account, repeat the steps 16 - 23, 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-multiple-attachments
25. Click Finish.
26. Save the package.

ExpandedToggleIcon        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.

ExpandedToggleIcon        Creating Package

1.Click Integration in the menu on the left side of the page.
2.Click the New button in the top right corner of the page.
3.Click Import.
4.Select Salesforce1 in the Target Connection drop-down list.
 
target-connection-selection

ExpandedToggleIcon        Importing Accounts

1.Click the + Add task to open the Import Wizard.
2.Click Upload and select the CSV file with Accounts data to import.
 
upload-csv-file
3.If necessary, set the CSV Options.
 
csv-options
4.Click the Next button in the bottom of the dialog box. You can also switch between the Import Wizard pages by clicking the corresponding icons in the wizard header and return to previous wizard page by clicking the Previous button.
5.Select Accounts in the Target list and then click Next.
6.Map the Account fields to the corresponding source columns.
7.Click Finish.

ExpandedToggleIcon        Importing Attachments

1.Click the + Add Task to open the Import Wizard.
2.Click browse and select the CSV file with Attachments data to import.
 
upload-csv-file
3.Click the Add zip with binary data link.
 
link-binary-data
4.Click browse and select the zip file with attachments to import.
 
upload-zip
5.If necessary, set the CSV Options.
 
csv-options
6.Click the Next button in the bottom of the dialog box. You can also switch between the Import Wizard pages by clicking the corresponding icons in the wizard header and return to previous wizard page by clicking the Previous button.
7.In the Target list select Attachment and then click Next.
8.Click the ParentID field and then, in the Column drop-down list, select Relation.
9.In the Referenced Object drop-down list select Accounts.csv.
10.In the Column drop-down lists select Account Name.
11. In the Referenced Column drop-down lists select Name.
 
attachment-relation-mapping
12. Repeat the steps 7 - 10 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).
 
zip-file-mapping
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).
 
content-type-expression
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 Finish.
21. Save the package.