Moving Data Between Salesforce Orgs: A How-To Guide
In this article
Moving data between Salesforce orgs is a common task when you're merging companies, setting up a sandbox for testing, or migrating to a new instance. This guide covers the practical steps to export data from one org, import it into another, and verify the results so you know the move was successful. Before you start, you'll need at least a basic understanding of Salesforce objects, fields, and the Data Export service, plus the necessary permissions to access data and perform imports.
What You'll Need
- Access to both the source and target Salesforce orgs with appropriate permissions (e.g., System Administrator or a custom profile with API and data management permissions).
- Salesforce Data Export service (available in Setup) or a third-party tool like Data Loader (free, but requires installation and a login to the org).
- A CSV file editor (like Excel or Google Sheets) to review and clean data.
- Knowledge of the objects and fields you're moving, especially custom objects and their relationships.
- For large data volumes or complex migrations, consider using Salesforce-to-Salesforce (S2S) or a dedicated migration tool, but for this guide we'll focus on the standard export/import approach.
Step-by-Step
- Plan what to move. Identify the objects and fields you need. For example, you might move Accounts, Contacts, and their related Opportunities. Decide whether you need historical data or just current records.
- Prepare the target org. Ensure the target org has the same objects and fields as the source. If you have custom objects, create them in the target org first, matching API names and field types as closely as possible.
- Export data from the source org. Go to Setup > Data > Data Export in the source org. Choose the objects you want to export, and set the date range. You can export all data or a specific date range. Click Export Now or schedule a weekly export. Salesforce will email you a link to download a ZIP file containing CSV files for each object.
- Download and inspect the export files. Extract the ZIP file. Open each CSV in a spreadsheet editor to review the columns and data. Check for any field types that might not import cleanly, like picklists that don't exist in the target org.
- Clean and map the data. If the target org has different field names or picklist values, you'll need to map them. Create a new CSV with the target org's field names as column headers, and copy the data from the source CSV, adjusting values as needed. For example, if a picklist value is "NY" in the source but "New York" in the target, update the CSV.
- Import data into the target org. Use Data Loader (or the built-in Data Import Wizard for simple objects). In Data Loader, choose Insert or Upsert (if you have external IDs). Map the CSV columns to the target org's fields. For relationships, use the external ID field if you have one, or map the parent record's ID (but note that IDs will differ between orgs).
- Run the import and check the results. After the import, Data Loader will show success and error files. Review the error file for any failed records and fix them in the CSV, then re-import only the failed records.
- Verify the data in the target org. Use reports or SOQL queries to compare record counts between source and target. For example, run a report on the source org for total Accounts, then run the same report on the target and compare. Also spot-check a few records for field-level accuracy.
- Verify relationships. If you moved parent and child records, verify that lookups are correctly populated. For example, check that Opportunities are linked to the right Accounts. You can do this by exporting both objects from the target and checking that the parent IDs match the new Account IDs.
- Document the migration. Keep a record of what was moved, when, and any issues encountered. This helps with audits and future migrations.
Common Mistakes
- Not preserving IDs. Salesforce IDs are unique per org, so you can't just copy the ID field. Use external IDs or map relationships by a unique key (like Account Name or a custom external ID field).
- Ignoring field types. Date fields, picklists, and formulas can cause issues. For example, formula fields are read-only and can't be imported. You'll need to recreate them in the target org.
- Overlooking required fields. If a field is required in the target but not in the source, the import will fail. Add those fields to your CSV with appropriate values.
- Importing in the wrong order. If you have parent-child relationships, import parents first so you have their new IDs to link children. Otherwise, you'll have to do a second pass to update lookups.
- Not checking for duplicates. If you're merging two orgs, you might end up with duplicate records. Use Salesforce's duplicate rules or do a manual check before importing.
Tips
- Use external IDs. If your data has a natural unique key (like a customer number), create a custom external ID field in both orgs and map it. This allows you to use Upsert and simplifies relationship mapping.
- Test in a sandbox first. Try the migration in a sandbox that mirrors your target org to catch issues without affecting production data.
- Use the Data Import Wizard for simple objects. For standard objects like Accounts and Contacts, the Data Import Wizard (Setup > Data > Data Import Wizard) is easier and doesn't require a separate tool.
- Batch your imports. If you have a large volume, break it into smaller batches (e.g., 10,000 records at a time) to avoid timeouts and make troubleshooting easier.
- Backup everything. Always export a full backup from the source org before starting, in case you need to roll back.
Troubleshooting
- Import fails with "INVALID_FIELD" error. This usually means a field name in your CSV doesn't match the target org. Check the exact API names in the target (Setup > Object Manager > Field & Relationships).
- Records import but lookups are empty. This happens when you didn't map the relationship correctly. Use external IDs or update the lookup fields after import with a second Data Loader operation.
- Data Export email never arrives. Check the email address associated with your Salesforce admin account, and check your spam folder. Also, ensure you have the "Data Export" permission.
- CSV file is too large to open in Excel. Use a text editor or a tool like OpenRefine to handle large files. Or split the CSV into smaller parts.
- Picklist values don't match. If the target org has a picklist with restricted values, you'll need to either add the missing values to the target picklist or update your CSV to use valid values.
- Import succeeds but record counts don't match. This could be due to duplicates, records that failed silently (check the error file), or records that were merged. Re-run the counts and check for duplicates.
Frequently Asked Questions
Q: Can I move data between Salesforce orgs without any third-party tool?
A: Yes, you can use the built-in Data Export and Data Import Wizard for standard objects. For custom objects or large volumes, you might need Data Loader, which is free but requires installation.
Q: What is the best way to preserve relationships between records?
A: Use external IDs. Create a custom field in both orgs to store a unique identifier, then map that field when importing. This allows you to link child records to parents by the external ID instead of the Salesforce record ID.
Q: How long does a data migration take?
A: It depends on the volume and complexity. A small migration with a few thousand records can be done in a few hours, while a large, complex migration might take days. Plan for time to clean data and verify results.
Q: Can I move data from a sandbox to a production org?
A: Yes, the same process applies. However, be careful with external IDs and picklist values that might differ between sandbox and production.
Q: What should I do if some records fail to import?
A: Download the error file from Data Loader. It will show the reason for each failure. Fix the data in the CSV and re-import only the failed records.
Q: Is it possible to automate data migration?
A: Yes, you can use Salesforce APIs (like Bulk API) and scripting to automate the process. Data Loader also supports command-line operations for scheduling.