Importing and exporting data

Salesforce provides a number of its own tools for importing and exporting data, as well as a number of third-party options based on the Salesforce APIs; these are listed on AppExchange. When importing records with other record relationships, it is not possible to predict and include the IDs of related records, such as the Season record ID when importing Race records; this section will present a solution to this.

Salesforce provides Data Import Wizard, which is available under the Setup menu:

Importing and exporting data

It is straightforward to import a CSV file with a list of race Seasons since this is a top-level object and has no other object dependencies. However, to import Race information (which is a related child object to Season), the Season and Fasted Lap By record IDs are required, which will typically not be present in a Race import CSV file by default. Note that IDs are unique across the platform and cannot be shared between orgs.

Tip

If you need a reminder of the structure of these objects, refer to the Schema Builder screenshot shown in Chapter 2, Leveraging Platform Features.

External ID fields help address this problem by allowing Salesforce to use the existing values of such fields as a secondary means to associate records being imported that need to reference parent or related records. All that is required is that the related record Name or, ideally, a unique external ID be included in the import data file.

The Races.csv file is included in the sample code for this chapter in the /data folder. This CSV file includes three columns: Year, Name, and Fastest Lap By (of the driver who performed the fastest lap of that race, indicated by their Twitter handle). You may remember that a Driver record can also be identified by this since the field has been defined as an External ID field:

Importing and exporting data

Both the 2014 Season record and the Lewis Hamilton Driver record should already be present in your packaging org. If not, refer to the previous chapter to create these. Now, run the Data Import Wizard and complete the settings as shown in the following screenshot:

Importing and exporting data

Next, complete the field mappings as shown in the following screenshot:

Importing and exporting data

Click on Start Import and then on OK to review the results once the data import has completed. You should find that four new Race records have been created under 2014 Season, with the Fasted Lap By field correctly associated with the Lewis Hamilton Driver record.

Tip

Note that these tools will also stress your Apex Trigger code for volumes, as they typically have the bulk mode enabled and insert records in chunks of 200 records. Thus, it is recommended that you test your triggers to at least this level of record volumes. Later chapters will present coding patterns to help ensure that code supports the bulk mode.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.15.43