Account1 won't have been set because it refers to the ID of
Account2 in the source org, not the org we're upserting into.
Account2 might not even exist at the time
Account1 is created, meaning there's no record to set the
To workaround this, you'll need to do a few steps:
- Upsert the Accounts without
Account2 in the target.
- Create a new CSV containing the
Id field and the
ParentId, where these ID fields are the IDs created in step 1, not the IDs from the source org.
- Update the Accounts with this new CSV file, to set the
If you have records with the
ParentId set in a Salesforce org, Gearset has a data deployment feature which allows you to do all of this in one operation. Full disclosure: I'm a software engineer at Gearset.
It does this by breaking the operation into a few parts:
- Fetch Account records which match a filter (or up to 30,000 records).
- Fetch any Account records which are parents of the records in step 1.
- Upsert the Account records without setting the
- Update the Account records to set the
This is the same as the method described above, but you don't need to worry about IDs yourself.
There's a 30 day free trial if you'd like to give Gearset a go. Feel free to get in touch if you have any questions!
Here's a summary of how to do the deployment in Gearset.
Select the source org (which has the
ParentId set) and the target org (which has a
Account object. You can optionally filter which Account records will be deployed if you're only interested in deploying a subset of the records.
upsert records for Account and choose
ExternalId__c as the field. This external id must exist in both the source and target org.
Click to deploy. Gearset will fetch any Account records matched by your filter (or up to 30,000 records if there was no filter) and any Account records which are a parent of those initial records. Gearset will then upsert all of these Account records, and update the records to set the