Write a trigger to automatically populate Account shipping address fields with billing address fields if Copy_Billing_To_Shipping__c checkbox is checked.
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;
}
}
}
apex-triggertriggercodingscenario