Sunday 23 November 2014

Dataloading with External IDs

Dataloading with External IDs

With the use of External IDs, painstaking data-loading exercise can be made really simple and 
straight forward. In Salesforce, a classic use-case is to data-load into Many to Many relationships. 
Usually, in order to data-load M2M relationships we insert master objects, extract their ids and
 then match master objects ids with child records manually or using VLookup functionality available
 in MS-Excel. If we have to repeat the data-load into a separate Sandbox or Production environment
 we have to do the same task again as the id's of different environments are not the same. But with
 External IDs, we can make this painful process simpler and quicker.

How to use External IDs to data-load into a Junction Object

For example imagine we are trying to data-load to a junction object named "Account Contact Lookup".
Master objects of this junction object are "Account" and "Contact". Below are the steps need following
 in order to successfully data-load in to "Account Contact Lookup" object.

1. Create two External ID fields on each Master Object; in this case both Account and Contact - Format
 of external Ids can be unique text field or auto number. If you are importing data from a different system
 and you already have a primary key for master objects, you can use a text field(external id) to populate
your external ids. 

2. Insert Master object records (Account and Contact) into the database and populate external Ids.

3. If you are importing data from another system and in the data file for Account Contact Lookup object,
if you have both primary keys for Account and Contact now you can do a upsert on Account Contact
Lookup using Salesforce Data-loader tool.

4. In the first step of the dataloader wizard, select ID as the unique reference. Then in the second step,
you can select external Id field for matching for each object. After selecting relevant external id fields,
you can map Primary Keys in the data files to external id fields of Account and Contact objects in step three. 

5. In the last step select Upsert to create Account Contact Lookup records.

No comments:

Post a Comment