Importing data through Data Loader
Now, I'm going to be completely honest; in the 10 years I've worked with Salesforce, this is the method I have used the least. I honestly don't know why, because it's easy to use, but I find myself using Data Loader much more, because it has the most capabilities and I guess I just got used to always using the same tools for importing and exporting.
So, for the next steps, we'll be using Data Loader. As mentioned before, Data Loader is an application that needs to be installed on your computer. So, let's do that first.
- Navigate to Setup | Integrations | Data Loader to find the download files for Windows or Mac:
- Select the one that suits your operating system and install it; you'll need administrator rights on your PC. Accept the license agreements. You can also leave the default install location as it is.
- Once installed, double-click the cloud icon on your desktop, representing Data Loader, to run the application. Let's first set some settings by clicking Settings on the menu. Please make sure that you set your settings exactly the same as mine, as shown in the following screenshot:
- Okay, let's prepare our Movie file for import now! Open up the Movie.csv file from the resources zip folder. Ensure that the Director__c column is blank and that we have the Director__R.Name column next to it. The Name column contains the name of the Person record. We'll be using this name to do a VLOOKUP into the Person.csv file we just exported, containing the record IDs, to populate our Director__c column:
- Simultaneously, open up the exported Person.csv file. Now, to do a correct VLOOKUP, it's important that the value we search for to return the corresponding value from another column is on the right of the result! So, select the whole Name column from the person file, right-click, and select Cut.
- Then, select the whole Id (first column) column, right-click, and select Insert Cut cells. This will result in the Name column being before the Id column and the rest of the data staying untouched, like so:
- Great, now we'll be performing our VLOOKUP in the Movie file, in which we want to populate the record ID, found in our Person file, corresponding to the Director_R.Name value from the Movie file for each record in the file!
- So, navigate to your Movie file and click the first empty cell in the Director__c column and type the following VLOOKUP formula in that cell:
= VLOOKUP(H2,Person__c.csv!$A:$B,2,FALSE)
=VLOOKUP (The value you want to look up (the director name for that row), the range where you want to lookup the value (search for the name in our Person__c.csv file in columns A and B, because A contains the values to search in and B contains the record ID we want as result if the name is found!), the column number in the range containing the return value (so the return value of our record ID is in the second column of the selected range columns A and B), exact match or approximate match—indicated as 0/ FALSE or 1/ TRUE (we set FALSE, so we want an exact matching name found!)).
- When you hit enter, after having typed the formula, you should see that the first cell gets populated with the corresponding ID from the person file for the director name on the same row:
But now, we need this formula in every cell of that column, or at least for each record. To copy the formula down for each record, move your mouse to the right-bottom corner of the cell containing your formula until you see the cursor change to a little black cross or plus (+) sign. If your cursor changed to the plus sign, then click (and hold) and drag your mouse down until the last corresponding cell is highlighted. Then, let go of your left mouse-click and your cells will be populated with each corresponding ID:
Great, but please note that the values in this column are not ready to be imported yet, because they contain formulas! That's a big no when importing the data, because, at import, they won't contain the actual values! So, we need one more step, and that's replacing those values with the actual data!
- This is simple—just click the Director__c column header so that the whole column is selected, right-click and select Copy, then, on the same column, right-click again and select Paste Special, and, in the little popup, select Values and click OK:
- To verify that the formula has been replaced by the actual value, click in one of the Director__c cells, and in your menu bar you should see the record ID and not the VLOOKUP formula anymore!
- Now, save your Movie.csv file so that you have the latest version, including the Director__c IDs. You should get used to doing VLOOKUP a lot, because, when loading data into Salesforce, this is an action you will need to be performing a lot. Thanks for being patient, I won't be holding off any longer. Let's import this file right now!
- Start Data Loader. We'll be performing an insert (creating new records into our database), so click the Insert button.
- Data Loader will ask you to connect to your Salesforce org, so choose Password Authentication, fill in your login credentials (username and password), and click Login. It should display a Login successful message, and the next button should get enabled. Hit the Next button after successful login.
- The next step will ask you which object you'd like to insert. In our case, that's the Movie__c object. You should also select your import file, so browse your folders and select the Movie.csv import file you have just saved, including the director IDs:
- When you have selected the Movie object and selected your import file, hit Next, and a pop-up message will tell you how many records you are going to import. Click OK.
- In the next step, it will read the columns from your CSV, and you'll have to map them to their corresponding fields in Salesforce:
- Click the Create or Edit a Map button. This opens a screen where, on top, you will see the Salesforce fields that have not been mapped yet for the selected object. In the bottom pane, you see the columns from your .csv file. Now click the button on top, Auto-Match Fields to Columns; this will automatically map fields and columns if the name corresponds:
In our case, it was able to map every field from the Movie object to a column, except for Owner ID. If our .csv file would have had an Owner ID, it could have mapped it too, but we didn't have that column. If no Owner ID is provided, the user doing the import will automatically become the owner of the records.
On the other hand, we can see that our Director_R.Name column will not be matched to any Salesforce field, and we don't have any left. This is correct because our Movie object does not have a director name field; it only has the Director lookup. The special thing about lookups is that, to load them, you need to provide the record ID, but, when you look at the field containing a value in Salesforce, a user will see the name of the corresponding record and not the ID. Cool, right? So, if you have mapped exactly like the preceding screenshot, you are ready to import, so click OK and then click Next.
- The last step asks you where you would like the success and error files to be saved; the Data Loader will provide this automatically after the import. The success file will contain all the records, including the newly created Salesforce record ID that was successfully inserted. The error file will contain all records that failed with a clear error message stipulating why it failed. So, let's click Finish to start the import. You'll get a pop-up message telling you how many successes and errors you had; in our case, six successes and no failures.
- Now, let's have a look in our BIM DB app on the Movies tab to find out whether we can see our six records and whether the director has been correctly related. As you can see in the following screenshot, the records are in:
- You will probably not see the cover images in your list view, but it looks nice anyway. You would like them, too! Now, select the All list view, instead of Recently Viewed, and then click the wrench icon on the right (right under the New button). Then Select Fields to Display:
- Select the columns (up to 10) that you'd like to see in your list view and change the order to your liking. I chose our Cover Image formula field as the first column.
- Click our The Godfather record so that we can check whether our director, Francis Ford Coppola, has been correctly filled in and related:
Yep, it has! Perfect, you have done your first import through Data Loader, including a VLOOKUP to relate records from another object!
We aren't done yet! With what you have learned so far, you should be able to import the following files (Cast, Production Companies, and Reviews) in exactly the same manner!
So, next up is Cast, but for cast, we will need the IDs of our newly imported Movie records, and also the ID's of our Person records (we already have this file from our first export).