How can I set External ID for the object without exporting its records?


How do I define, which column is used to make a lookup to a different External ID field?

When I have a query that does a lookup to the Contact object to get the contact ids, it by default uses the Name column to do the lookup.
However the standard Name is not a queryable field on several objects.

Sample Query: SELECT Id, Name, Contact__c FROM Contact_Method__c

Log dump:

[16:07:28.321] Getting metadata for Contact (SOURCE)
[16:07:30.190] Getting metadata for Contact (TARGET)
[16:07:33.441] The parent sobject Contact for the lookup field Contact_Method\__c.Contact__c has been included into the process. ***The externalId is set to 'Name'.***
SELECT Id, Name FROM Contact WHERE Name IN ('Test User1', 'Test User2'
ERROR at Row:1:Column:36
**field 'Name' can not be filtered in a query call.**
[16:08:16.583] Execution of the command sfdmu:run has been finished. Exit code 4 (COMMAND_EXECUTION_ERROR).


If you just want to set the External ID for the Contact object, you need to include Contact object in your export.json with "operation": "Readonly", then set the externalId property to another field, than Name. Such configuration will avoid exporting Contact records but will switch it's externalId from Name to the other key field.

Below is the sample configuration to Upsert the parent Account of the specific Contact. The Contact record remains untouched:

    "objects": [
            "operation": "Readonly",
            "externalId": "LastName", // This will be now the External ID instead of Name as by default
            "query": "SELECT Id, AccountId FROM Contact WHERE LastName = 'Smith'",
              "operation": "Upsert",
            "externalId": "Name",
            "query": "SELECT Id, Phone, TEST1__c FROM Account",
            "master": false // Allows SFDMU to locate only the Account record related to the given Contact
Last updated on 13th Nov 2023