ApexSensei

Drills SOQL queries

Find missing Contact emails

SOQL uses = null and != null to find fields that are empty or filled in.

Your task

Split this run's Contacts into those with no Email and those with an Email.

String tag = 'AS-Q305-' + UserInfo.getUserId() + '-' +
    String.valueOf(Datetime.now().getTime());
Account parent = new Account(Name = tag);
insert parent;
String presentEmail = 'q' + String.valueOf(Datetime.now().getTime()) + '@example.com';
List<Contact> seeded = new List<Contact>{
    new Contact(LastName = tag + '-Null', AccountId = parent.Id, Email = null),
    new Contact(LastName = tag + '-Present', AccountId = parent.Id, Email = presentEmail),
    new Contact(LastName = tag + '-Blank', AccountId = parent.Id, Email = '')
};
insert seeded;

List<Contact> missing = new List<Contact>();
List<Contact> present = new List<Contact>();
System.debug('Null missing: ' + missing.size());
System.debug('Null present: ' + present.size());
System.debug('Null blank is missing: false');
System.debug('Null present excluded: false');

Requirements

  1. Null missing: 2 should be built from the query result
  2. Email = null should be present
  3. Email != null should be present
  4. Null missing: 2 should be printed
  5. Null present: 1 should be printed
  6. Null blank is missing: true should be printed
  7. Null present excluded: true should be printed

Sign in to open this drill