What is the proper way to include lookup field in my query?

Question.

I want to migrate self-referenced account records.
I am using the query below, but it does not work for me:

SELECT Name, Parent.External_ID__c, Parent.Id from Account

The external Id key for the Account object is "External_ID__c".

Answer:

You can't use dot in your queries. And you don't need to specify the parent's external id field (External_ID__c).

The proper way to include lookup fields in your migration is like that:

SELECT Name, ParentId from Account

It is the same format like if you want to transfer a lookup of different sObject type

Last updated on Sa Oct 2022