Can I include referenced fields, like Account.Name into the query string ?
Question:
I want to avoid including the Account object in export.json but still migrate the Name of the Account referenced by a given Contact. For example, like this:
{
"query": "SELECT Id, Account.Name FROM Contact",
"operation": "Upsert",
"externalId": "Name"
}
Can I do this?
Answer:
The query string does not support referencing fields using dot notation (e.g., Account.Name). Only fields that belong directly to the queried object can be included.
To achieve your goal, you need to explicitly include the Account object in export.json and establish a lookup relationship between Contact and Account, like this:
{
"objects": [
{
"query": "SELECT Id, AccountId FROM Contact",
"operation": "Upsert",
"externalId": "Name",
"master": true
},
{
"query": "SELECT Id, Name FROM Account",
"operation": "Upsert",
"externalId": "Name",
"master": false
}
]
}
This configuration:
- Exports all Contacts as master records (
"master": true). - Exports only Accounts that are related to the given Contacts via the
AccountIdlookup field ("master": false). - For Contacts, both the
NameandAccountIdfields are exported, while for Accounts, only theNamefield is exported.