为基于自定义字段匹配送货地址邮政编码和账单地址邮政编码的帐户创建 Apex 触发器

Create an Apex trigger for Account that matches Shipping Address Postal Code with Billing Address Postal Code based on a custom field

我想创建一个触发器,在插入或更新之前检查复选框,如果复选框字段为真,则将运送邮政编码(其 API 名称为 ShippingPostalCode)设置为与账单邮政编码 (BillingPostalCode) 相同。

触发器的代码应该是什么?

我建议使用 Process Builder 而不是代码。您可以轻松定义"if Match Billing Address is TRUE and BillingPostalCode is not blank, update ShippingPostalCode with the value of BillingPostalCode."的逻辑,实现起来会更快,更容易维护。
您可以在此处阅读有关 Process Builder 的更多信息:https://help.salesforce.com/articleView?id=process_overview.htm&type=5

如果您决定使用触发器,它看起来像这样:

trigger updateShippingPostalCode on Account (before insert, before update) {

    for(Account a : Trigger.new) {

        if(a.Match_Billing_Address__c && a.BillingPostalCode != null) {

            a.ShippingPostalCode = a.BillingPostalCode;
        }
    }
}