# When a Contact's Primary_Phone__c is updated on the primary Contact, sync that phone number up to the parent Account's Phone field.

**Topic:** Development · **Difficulty:** Easy · **Asked at:** Accenture, HCL, Birlasoft · **Tags:** apex-trigger, trigger, coding, scenario

Read it on the site: https://www.forcechallenges.com/interview-questions/when-a-contact-s-primary-phone-c-is-updated-on-the-primary-contact-sync-that-phone-number-up-to-the-parent

## Answer

Use `after insert, after update` on Contact. When a primary Contact's `Primary_Phone__c` changes, copy it to the parent Account.

```apex
trigger ContactTrigger on Contact (after insert, after update) {
    Map<Id, Account> toUpdate = new Map<Id, Account>();
    for (Contact c : Trigger.new) {
        if (c.Is_Primary__c && c.AccountId != null &&
            (Trigger.isInsert || c.Primary_Phone__c != Trigger.oldMap.get(c.Id).Primary_Phone__c)) {
            toUpdate.put(c.AccountId, new Account(Id = c.AccountId, Phone = c.Primary_Phone__c));
        }
    }
    if (!toUpdate.isEmpty()) update toUpdate.values();
}
```
Using a Map keyed by AccountId avoids duplicate-Id errors in the update list.

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