# Write a trigger to automatically populate Account shipping address fields with billing address fields if Copy_Billing_To_Shipping__c checkbox is checked.

**Topic:** Development · **Difficulty:** Easy · **Asked at:** Wipro, Tech Mahindra, Hexaware · **Tags:** apex-trigger, trigger, coding, scenario

Read it on the site: https://www.forcechallenges.com/interview-questions/write-a-trigger-to-automatically-populate-account-shipping-address-fields-with-billing-address-fields-if-copy

## Answer

Use `before insert, before update` so values are saved without extra DML.

```apex
trigger AccountTrigger on Account (before insert, before update) {
    for (Account a : Trigger.new) {
        if (a.Copy_Billing_To_Shipping__c) {
            a.ShippingStreet = a.BillingStreet;
            a.ShippingCity = a.BillingCity;
            a.ShippingState = a.BillingState;
            a.ShippingPostalCode = a.BillingPostalCode;
            a.ShippingCountry = a.BillingCountry;
        }
    }
}
```

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