ApexSensei

Drills Debugging

Fix a missing null check

Calling a method on a blank field throws Attempt to de-reference a null object.

Your task

Fix the handler so Leads with a blank Email are skipped, and every other Lead still gets its domain in Description.

public class AS_A276BDF2054F_EmailTidy {
    public static void beforeInsert(List<Lead> leads) {
        for (Lead lead : leads) {
            String email = lead.Email.toLowerCase();
            lead.Email = email;
            lead.Description = 'Domain: ' + email.substringAfter('@');
        }
    }
}

Requirements

  1. lowercasesEmailAndSetsDomain should pass
  2. leavesABlankEmailAlone should pass
  3. insertsWhenEveryEmailIsBlank should pass
  4. handlesMixedBulkOfTwoHundred should pass
  5. usesStringIsBlank should pass

Sign in to open this drill