官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 名山县| 苗栗县| 斗六市| 荔波县| 濮阳县| 蒙阴县| 涟源市| 蓝田县| 和田县| 贡嘎县| 中牟县| 泰和县| 彰武县| 怀柔区| 会理县| 永兴县| 鄂托克旗| 红桥区| 梧州市| 东源县| 合阳县| 星子县| 西宁市| 大石桥市| 迭部县| 赤峰市| 青岛市| 安多县| 大同县| 长泰县| 从化市| 邛崃市| 米林县| 长白| 体育| 乌拉特后旗| 镇巴县| 宜川县| 旺苍县| 博兴县| 屏南县|