ApexSensei

Drills Triggers

Keep a Contact count on Account

A rollup counts child rows on a parent by running one aggregate query, not by adding or subtracting 1 per event.

Your task

Finish the Contact trigger so each Account's NumberOfEmployees always equals its Contact count. Account has no generic counter, so the count is stored in that field.

trigger AS_CBF9D5C38E34_ContactCount on Contact (
    after insert,
    after update,
    after delete,
    after undelete
) {
}

Requirements

  1. countsInsertedContacts should pass
  2. recountsBothAccountsOnMove should pass
  3. recountsAfterDelete should pass
  4. recountsAfterUndelete should pass
  5. handlesBulkOfTwoHundred should pass
  6. keepsCostFlatFromTwoToTwoHundred should pass

Sign in to open this drill