# Prevent Deleting Contacts Linked to Open Opportunities

**Type:** Apex trigger · **Difficulty:** Hard · **Object:** Contact · **Topics:** Contact, Opportunity, Before Delete, Cross Object Validation

Practice this problem interactively (write and run your Apex trigger against realistic data): https://www.forcechallenges.com/problems/prevent-delete-contacts-linked-to-open-opportunities

## Problem

Before a Contact is deleted, check whether the Contact is selected as the custom Client_Contact__c on any open Opportunity. If so, block the deletion and explain why. Check all Contacts in the delete batch with one query.

## Constraints

Use bulk-safe trigger logic. Do not run SOQL or DML inside loops.

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