Exporting data
Data can be exported from Salesforce to .csv the files . Salesforce provides two methods for exporting data:
- Salesforce Data Export: This is an online tool available through Setup. It has a very simple interface, just like the Data Import Wizard. It lets you export data from any object. Exports can be scheduled on a weekly or monthly basis. When a scheduled export is ready for download, you will receive an email notification containing a link that allows you to download your file(s), and you can also access this link from the export page.
- Data Loader: Data Loader is a client application that you need to install. The tool accesses your org through the Salesforce API and lets you export any data. It comes with its own UI, but you could also run it through the command line (this makes it possible to automate and schedule exports).
The following table on differences between Data Export and Data Loader in Salesforce:
So, now that we know which tools exist, let's load some data in our BIM DB app using both tools. Before we start loading any data, I have made some fixes to our database that will make it easier for you to import data and make our cover image rendering better.
I removed the Cover rich text area field from the Movie object and added a Cover URL text field that will contain the full URL to the image hosted from IMDb (www.imdb.com) and a formula field that renders the image itself based upon that URL. Although I'll explain formulas in Chapter 3, Declarative Automation, I would like you to perform those modifications now, so that when we load data, we will all have the same data:
- Go to Setup | Object Manager | Movie object | Fields and Relationships.
- Then, next to the Cover field, click the arrow, select Delete, and confirm that you want to delete this field.
- On this Movie object, click New to create a new text field called Cover URL with a length of 255 characters:
- Now, create a new field type, Formula, with the output Text type, and call it Cover Image. In the formula editor, enter the following formula:
IMAGE( Cover_Url__c , "Cover", 150, 100)
- This is an image function that takes a URL (in our case, this references our Cover_Url__c field), a text value that is the caption for when you hover over the image, a height for the image (in our case 150 pixels), and a width for the image (in our case 100 pixels). Your screen should look like this once you have saved the field:
- Okay, let's check what we did now on our The Godfather movie record. Navigate to The Godfather record. It should look like the following screenshot:
You see our big cover-image field is gone. Which is good, because we deleted it and at bottom of the page there are now two new fields, Cover URL and Cover Image (which shows the icon of an irretrievable image). This is perfect, because we haven't entered the URL where the image is hosted. Let's do that.
- Edit the record and copy/paste https://m.media-amazon.com/images/M/MV5BM2MyNjYxNmUtYTAwNi00MTYxLWJmNWYtYzZlODY3ZTk3OTFlXkEyXkFqcGdeQXVyNzkwMjQ5NzM@._V1_SY1000_CR0,0,704,1000_AL_.jpg into the Cover URL field and save your changes. The formula now automatically renders the image based upon the URL you entered in the Cover URL field. This will make it easier for users to insert covers just by searching them on the internet and entering the URL in that field. It will also make it easier for the next steps when we load the same data.
- Let's load some data now. I have a couple of .csv files for you in the .zip folder; one for every object. Just to be safe and make sure we're on the same page here, we'll delete the test data we already created together. Go to the The Godfather movie record and hit Delete or from the Movies tab, click the little arrow on the right next to the movie you want to delete, and delete it.
- Do the same for Persons and for Companies. Delete all the data you already created. Remember that Cast and Production Companies were both master-detail relationships, so, by deleting Movie, Person, and Company, all those child records will also be deleted. I'm telling you this so you won't worry that you have no tab for them and you would not be sure how to delete those. In order to prevent issues on currency and date fields, adapt your user Locale Settings to the following:
Now that our database is clean and empty, we can begin. Because we have several objects to load and there are relationships between them, the order in which data is loaded is important. Just like we have built our app together in steps, we'll load data in steps, because, to load the related records, we'll need the generated Salesforce record ID to fill the lookup fields and master-detail fields with their corresponding record IDs.
So, the order we will load data in will be as follows:
- First, the stand-alone records:
- Person
- Company
- Then, our movie records, because they have a direct lookup filled to a Person for the Director field!
- Finally, all the related records:
- Cast
- Production Company
- Review
This also means that we'll be exporting data once it's created, so we have their corresponding record IDs, and then, in Excel, we'll be attaching those IDs, where needed, with a VLOOKUP function.