ApexSensei

Drills DML operations

Insert a tagged Account

insert saves a new record and writes the new Id back onto the same variable.

Your task

Insert one uniquely tagged Account and check the saved row by its new Id.

String tag = 'AS-INSERT-' + UserInfo.getUserId() + '-' +
    String.valueOf(Datetime.now().getTime());
Account acct = new Account(
    Name = tag,
    Description = 'Created by ApexSensei'
);

List<Account> saved = new List<Account>();

Requirements

  1. insert acct; should be present
  2. Id = :acct.Id should be present
  3. No Id yet should be printed as Id before insert: null
  4. The new Id should be printed as Id assigned: true
  5. The saved row should be printed as Saved count: 1
  6. The saved Name should be printed as Name matches: true

Sign in to open this drill