External ID matching on upsert
Key Takeaway
An upsert uses a matching field, either an external ID or the Salesforce record ID, to decide for each row whether to update an existing record or create a new one.
Upsert combines insert and update in one operation. An external ID is a custom field with the External ID attribute that stores a record's identifier from a system outside Salesforce. Matching on an external ID lets you bring in data from another system without creating duplicate records.
How an upsert decides for each row
For each row in the file, the upsert looks for an existing record that matches on the matching field.
If a row matches an existing record...
The upsert updates that record with the file's values.
If no match is found...
The upsert creates a new record.
For example, imagine you upsert a file of records from another system and match on an external ID field. One row has the value INV-100, and a record in Salesforce already has that value, so the upsert updates that record. The next row has the value INV-101, and no record has that value, so the upsert creates a new record.