The upsert DML operation creates new sObject records and updates existing sObject records within a single statement, using an optional custom field to determine the presence of existing objects.
This example performs an upsert of a list of accounts.
List<Account> acctList = new List<Account>(); // Fill the accounts list with some accounts try { upsert acctList; } catch (DmlException e) { }
This next example performs an upsert of a list of accounts using a foreign key for matching existing records, if any.
List<Account> acctList = new List<Account>(); // Fill the accounts list with some accounts try { // Upsert using an external ID field upsert acctList myExtIDField__c; } catch (DmlException e) { }
No comments:
Post a Comment