本篇参考:

https://developer.salesforce.com/docs/atlas.en-us.234.0.apexref.meta/apexref/apex_methods_system_custom_metadata_types.htm

https://trailhead.salesforce.com/en/content/learn/modules/platform-developer-i-certification-maintenance-winter-22/learn-whats-new-for-platform-developers-22

我们都知道salesforce里面 custom setting的使用方法,不了解的小伙伴可以开启时空门:salesforce 零基础学习(四十)Custom Settings简单使用

custom setting好用是好用,但是理解起来可以理解成特殊的表,数据还是要维护的,所以针对不同的sandbox或者生产环境,可能会有一些 manual action来维护数据或者初期的导入。所以针对 list类型的 custom setting,官方更建议使用 custom metadata type来维护。我们可以通过metadata的方式来部署这些内容,这样可以尽最大的可能去减少因为遗漏导致的数据不完整从而导致业务处理有问题的情况。

salesforce 零基础学习(四十)Custom Settings简单使用-LMLPHP

那我们之前在使用 custom metadata type特别烦人的地方是,我们需要通过搜索数据的方式来获取数据,使用方式很类似我们object的query。比如下面的demo

System.debug(LoggingLevel.INFO, '*** Limits.getQueryRows(): ' + Limits.getQueryRows());
Country_Code__mdt countryCode = [
  SELECT Id, MasterLabel, Country_Code__c
  FROM Country_Code__mdt
  WHERE MasterLabel = 'Canada'
  LIMIT 1
];
System.debug(LoggingLevel.INFO, '***after Limits.getQueryRows(): ' + Limits.getQueryRows());
02-08 02:33