๐ How to Handle Lookup Relationships When Importing Data
When importing data into Salesforce, handling lookup relationships properly is essential to maintain data integrity and ensure correct linking between objects like Accounts, Contacts, Opportunities, and custom objects.
This guide explains how to import records that include lookup fields, ensuring they correctly relate to existing Salesforce records.
๐ What Is a Lookup Relationship?
A lookup relationship in Salesforce links one object to another. For example:
- A Contact may have a lookup to an Account.
- A Custom Object may have a lookup to a User or another custom object.
During import, these links must reference the correct Record ID or a unique external identifier.
๐งฐ Tools You Can Use
Tool | Supports Lookup Relationships? | Best For |
---|---|---|
Data Import Wizard | โ (with limitations) | Basic imports, standard objects |
Data Loader | โ (more flexibility) | Large volumes, custom objects |
Dataloader.io | โ (user-friendly) | Cloud-based data handling |
API/Bulk API | โ (programmatic control) | Automated or complex imports |
๐ Step-by-Step: Handling Lookup Relationships During Import
Option 1: Use Salesforce Record IDs
This is the most direct and reliable method.
๐น Example: Importing Contacts with Account Lookup
FirstName | LastName | AccountId |
---|---|---|
John | Doe | 0015g00000abcdef123 |
Jane | Smith | 0015g00000ghijkl456 |
Steps:
- Export existing Accounts to get their Record IDs.
- Include those IDs in the import CSV under the
AccountId
column. - Use Data Loader or Data Import Wizard to upload the Contacts.
โ
Pros: Accurate, avoids duplicate matches
โ ๏ธ Cons: You must obtain and manage record IDs
Option 2: Use External IDs
If you don’t want to rely on Salesforce record IDs, use a field marked as an External ID.
๐น Example: Importing Contacts with Account lookup via External ID
Assume your Account
object has a field called External_Account_Code__c
marked as External ID.
FirstName | LastName | Account:External_Account_Code__c |
---|
John | Doe | ACC001 |
Jane | Smith | ACC002 |
Steps:
- Ensure the related objectโs External ID field is unique and indexed.
- In your CSV, use the syntax:
ObjectName:ExternalID_Field__c
(e.g.,Account:External_Account_Code__c
) - Import via Data Loader or Dataloader.io with mapping.
โ
Pros: More human-readable, no need for record ID
โ ๏ธ Cons: External ID must be unique and already exist in Salesforce
๐ Using Data Loader for Lookup Imports
- Prepare Your CSV with either:
- Record IDs (
AccountId
) - External IDs (
Account:External_ID__c
)
- Record IDs (
- Open Data Loader
- Choose Insert or Upsert
- Map Fields
- Ensure your lookup field is mapped correctly to either the ID or External ID
- Run Import
- Review success and error files
๐ Tips & Best Practices
- Always load parent records first (e.g., Accounts before Contacts).
- If using External IDs, make sure they are:
- Marked as External ID in field settings
- Populated in the system before import
- Test a small sample before full import
- Use Upsert instead of Insert to avoid duplicates
- Keep backup of your original data
โ FAQs
Q: What if the referenced record (lookup) doesnโt exist?
A: The row will fail to import. Load parent data first, or use Upsert.
Q: Can I create lookup records during the same import?
A: Not directly. You must import parent records first, then the child.
Q: Can I use the Data Import Wizard for custom object lookups?
A: Only if the lookup is to a standard object and the external ID is properly set.