Salesforce: 无法在trigger中取到Country或State的更新

如果在org中启用了“State and Country Picklists”, 则无法在Trigger中获得Country或State的更新(适用于BillingCountry, BillingSate, MailingCountry, MailingState等)

例如,如下代码无法正常工作:

trigger MyAccountTrigger on Account (before update) {
  for (Account account : Trigger.new) {
    if (account.BillingCountry != Trigger.oldMap.get(account.Id).BillingCountry) {
    account.Name = 'test';
    }
  }
}

我们需要在Country或State后面加上Code

trigger MyAccountTrigger on Account (before update) {
  for (Account account : Trigger.new) { 
    if (account.BillingCountryCode != Trigger.oldMap.get(account.Id).BillingCountryCode) {
    account.Name = 'test';
    }
  }
}

这样就可以工作了。

原文地址:https://www.cnblogs.com/clsriz/p/14086963.html