ApexSensei

Drills SOQL queries

Bind an Account name

A bind variable puts an Apex value into SOQL with :variable.

Your task

Find the Account whose name has an apostrophe, then show that a bound missing name returns zero rows.

String tag = 'AS-Q304-' + UserInfo.getUserId() + '-' +
    String.valueOf(Datetime.now().getTime());
String wantedName = tag + '-O\'Brien';
List<Account> seeded = new List<Account>{
    new Account(Name = wantedName),
    new Account(Name = tag + '-Decoy')
};
insert seeded;

Integer foundCount = -1;
Integer missingCount = -1;
System.debug('Bind found: ' + foundCount);
System.debug('Bind quote safe: false');
System.debug('Bind missing: ' + missingCount);
System.debug('Bind decoy excluded: false');

Requirements

  1. Database.query( should be absent
  2. Name = :wantedName should be present
  3. A second Name = :<variable> should be present
  4. Bind found: 1 should be printed
  5. Bind quote safe: true should be printed
  6. Bind missing: 0 should be printed
  7. Bind decoy excluded: true should be printed

Sign in to open this drill