# Block Account Status Changes When Contacts Exist

**Type:** Apex trigger · **Difficulty:** Hard · **Object:** Account · **Topics:** Account, Contact, Cross Object Validation, Bulkification

Practice this problem interactively (write and run your Apex trigger against realistic data): https://www.forcechallenges.com/problems/block-account-status-change-with-contacts

## Problem

An Account has a custom Status__c field. If a user changes Status__c and the Account has any related Contacts, stop that Account's update with a clear error. Accounts without Contacts can change status. Check all Accounts in the batch with one query.

## Constraints

Use bulk-safe logic. Do not run SOQL or DML inside loops. Handle missing or optional values safely.

---
Source: ForceChallenges · last updated 2026-10-13
