How to upsert using External Id using Apex in Salesforce?

Sample Code:

upsert listAccount Account.Fields.External_Field__c;

here listAccount is the List<Account> and External_Field__c is an External field.

Upsert uses the sObject record's primary key (the ID), an idLookup field, or an external ID field to determine whether it should create a new record or update an existing one:

1. If the key is not matched, a new object record is created.
2. If the key is matched once, the existing object record is updated.
3. If the key is matched multiple times, an error is generated and the object record is neither inserted or updated.

Cheers!!!

No comments:

Post a Comment