Upsert: insert or update
upsert inserts when no match exists and updates when one does.
Your task
Upsert the same tagged Account twice with Database.upsert: the first call inserts and the second updates.
String tag = 'AS-UPSERT-' + UserInfo.getUserId() + '-' +
String.valueOf(Datetime.now().getTime());
Account acct = new Account(Name = tag, Description = 'First pass');
Database.UpsertResult firstResult;
Id insertedId;
Database.UpsertResult secondResult;
List<Account> matches = new List<Account>();Requirements
Database.upsert(...)should be present.isCreated()should be presentId = :insertedIdshould be present- The first result should be printed as
First upsert created: true - The second result should be printed as
Second upsert created: false - The single row should be printed as
Match count: 1 - The second Description should be printed as
Saved description: Second pass