Upsert operation in Salesforce

Upsert opeation makes use of the sObject record's primary key( Record Id) or the external ID, if specified to determine whether new records should be created or else we have to update the existing records.
  • If the key is not matched, then a new record is created.
  • If the key is matched once, then the existing record is updated.
  • If the key is matched multiple times, then an error is generated and the object record is neither inserted nor updated.