Build Apps Like a Pro

Achieve App Builder Certification Become an App Builder Pro

Using DataLoader with Lookup Fields

External Ids provide a convenient way to integrate data from an external system, by allowing the use of a unique record identifer for records instead of the Salesforce Id.

For example, you may define an Account Code external id on the Account object, which is the unique key for an account record in an ERP system that is integrated with Salesforce. When using DataLoader or another integration tool to update data, the external id can be used instead of the Salesforce id to uniquely identify records.

External Ids can also be used when you need to load data into an object that has lookups, and the objects that the looksups are associated with have external ids defined. This makes loading data much simpler, than having to supply the salesforce ids for each lookup field.

Lets look at a case where we have an object that stores Customer Transactions, and it is loaded with data from an external system. The object has 4 fields, Account, Product, Transaction Amount and Transaction Date. Account and Product are lookups to their respective objects.

Salesforce Transaction Object

The Account object has an external id defined – Account Code.

Salesforce Account External Id

The Product object also has an external id defined, Product Code.

product-external-id-field

We have an account record with an Account Code defined:

american-bank

And also a product record with an External Product Code:

product-external-id

Now we want to load data using a CSV file into the transaction object, and use the external ids for the Account and Product. The csv file looks like this:

transaction-csv

Now we can use DataLoader to load the data.
The first step is to make sure you choose UPSERT and not INSERT. This will make sure that you will get the option to specify the external id fields.

Dataloader Upsert

Now at step 2a, you can choose the external ids for the objects:

dataloader-select-external-ids

Then when you get to the mapping step, map the external id fields to the relationship fields.

Salesforce Data Loader Mapping

And finally, our record is loaded with the lookup fields of account and product populated correctly.

transaction-record

 

What Certification are you studying for now?

Focus on Force currently provides practice exams and study guides for sixteen certifications