为基于自定义字段匹配送货地址邮政编码和账单地址邮政编码的帐户创建 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) 相同。
- 必须调用 Apex 触发器 'AccountAddressTrigger'。
- Account 对象需要一个新的自定义复选框,该复选框应该有
的字段标签 'Match Billing Address' 和字段名称
'Match_Billing_Address'。结果 API 名称应该是
'Match_Billing_Address__c'.
- 在 'AccountAddressTrigger' 处于活动状态时,如果帐户有账单
邮政编码和'Match_Billing_Address__c'为真,记录应该
将送货邮政编码设置为在插入或更新时匹配。
触发器的代码应该是什么?
我建议使用 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;
}
}
}
我想创建一个触发器,在插入或更新之前检查复选框,如果复选框字段为真,则将运送邮政编码(其 API 名称为 ShippingPostalCode)设置为与账单邮政编码 (BillingPostalCode) 相同。
- 必须调用 Apex 触发器 'AccountAddressTrigger'。
- Account 对象需要一个新的自定义复选框,该复选框应该有 的字段标签 'Match Billing Address' 和字段名称 'Match_Billing_Address'。结果 API 名称应该是 'Match_Billing_Address__c'.
- 在 'AccountAddressTrigger' 处于活动状态时,如果帐户有账单 邮政编码和'Match_Billing_Address__c'为真,记录应该 将送货邮政编码设置为在插入或更新时匹配。
触发器的代码应该是什么?
我建议使用 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;
}
}
}