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.
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. |
|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.|
|8.||Click the Save button to save the connection.|
|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.|
|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. |
|6.||Click the + Add task to open the Import Wizard. |
|7.||Click browse and select the CSV file with Accounts data to import.|
|8.||Click the Add zip with binary data link.|
|9.||Click browse and select the zip file with attachments to import.|
|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.|
|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. |
|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. |
|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.|