ApexSensei

Drills SOQL queries

Stream tagged Accounts

A SOQL for loop puts the query right in the loop header.

Your task

Count 201 tagged Accounts in chunks with a SOQL for loop, then run both loop forms on a query with no matches and count the passes.

String tag = 'AS-Q312-' + UserInfo.getUserId() + '-' +
    String.valueOf(Datetime.now().getTime());
String tagPrefix = tag + '%';
List<Account> seeded = new List<Account>();
for (Integer i = 1; i <= 201; i++) {
    seeded.add(new Account(Name = tag + '-' + i));
}
seeded.add(new Account(Name = 'OTHER-' + tag + '-Decoy'));
insert seeded;
String missingPrefix = tag + '-Missing%';

Requirements

  1. Row count should be computed from the loop
  2. List-form SOQL loop over :tagPrefix should be present
  3. One-row SOQL loop over :missingPrefix should be present
  4. Rows: should be 201
  5. Chunks: should be 2
  6. Empty loop: should be 0
  7. Empty chunk passes: should be 1

Sign in to open this drill