# Closed Won Makes a Customer

**Type:** Apex trigger · **Difficulty:** Medium · **Object:** Opportunity · **Topics:** after update, Trigger.oldMap, Bulkification

Practice this problem interactively (write and run your Apex trigger against realistic data): https://www.forcechallenges.com/problems/closed-won-marks-customer

## Problem

When an **Opportunity** moves to `StageName = 'Closed Won'` (i.e. it was *not* Closed Won before the update), set its parent **Account**'s `Type` to `'Customer'`.

Requirements:
- Only react to the **transition** into Closed Won — compare against `Trigger.oldMap`.
- Skip opportunities without an Account.
- Your trigger must be **bulk-safe**: at most **1 SOQL query** and **1 DML statement** per 200-record chunk, regardless of how many opportunities change.

## Constraints

- Use `Trigger.oldMap.get(opp.Id)` to read prior values.
- Collect Account Ids in a `Set`, then do one `db.update`.

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