- Check the below code
trigger AccountAddressTrigger on Account (before insert, before update) {
for (Account acct : Trigger.new) {
// 1) Skip every record where the checkbox isn’t checked
if (!acct.Match_Billing_Address__c) {
continue;
}
// 2) On update, only act if it just flipped from false → true
if (Trigger.isUpdate) {
Account oldAcct = Trigger.oldMap.get(acct.Id);
if (oldAcct.Match_Billing_Address__c) {
// it was already true before, so skip
continue;
}
}
// 3) Now we know Match_Billing_Address__c is true (newly checked or on insert)
// and we can safely copy the Billing postal code over
acct.ShippingPostalCode = acct.BillingPostalCode;
}
}
1 件の回答