Custom Metadata Allocations and Usage Calculations
Custom Labels
最近项目在对一些共通Apex用到的常量在讨论有什么好的解决方案。
目前有几种方式:
建立一个常量类,所有的常量都定义为public static final
。使用方法:常量类名.变量名
/*
* 定数共通処理
*/
public with sharing class EX_CommonConstants {
/** 会社コード */
public static final String COMPANY_CODE = ‘WZJ‘;
}
// 使用方法
system.debug(EX_CommonConstants.COMPANY_CODE);// output:WZJ
Custom labels enable developers to create multilingual applications by automatically presenting information (for example, help text or error messages) in a user’s native language. Custom labels are custom text values that can be accessed from Apex classes, Visualforce pages, Lightning pages, or Lightning components. The values can be translated into any language Salesforce supports.
自定义标签使开发人员能够通过以用户的本机语言自动显示信息(例如,帮助文本或错误消息)来创建多语言应用程序。自定义标签是可以从 Apex 类、 Visualforce 页面、 Lightning 页面或 Lightning 组件访问的自定义文本值。这些值可以翻译成 Salesforce 支持的任何语言。
You can create up to 5,000 custom labels for your organization, and they can be up to 1,000 characters in length. Custom labels from managed packages don’t count toward this limit.
您可以为组织创建多达5,000
个自定义标签,它们的长度可以达到1,000
个字符。来自managed packages
的自定义标签不计入此限制。
如何向应用程序添加自定义标签取决于用户界面。有关以下语法的详细信息,请参阅相应的开发人员指南。
System.Label.Label_name
syntax.$Label global
variable.$Label.c.labelName
syntax for the default namespace or $Label.namespace.labelName
if your org has a namespace or to access a label in a managed package.@salesforce/label/namespace.Label_name
syntax.{!$Label.customLabelName}
expression.添加Custom Labels
1000
个字符的文本。这个值可以翻译成 Salesforce 支持的任何语言。
使用方法
// 由常量类变成了 System.Label
system.debug(System.Label.COMPANY_CODE);// output:WZJ
Custom metadata is customizable, deployable, packageable, and upgradeable application metadata. First, you create a custom metadata type, which defines the form of the application metadata. Then you build reusable functionality that determines the behavior based on metadata of that type.
定制元数据是可定制的、可部署的、可打包的和可升级的应用程序元数据。首先,创建自定义元数据类型,该类型定义应用程序元数据的形式。然后构建基于该类型的元数据确定行为的可重用功能。
After you create a public custom metadata type, you or others can declaratively create custom metadata records that are defined by that type. When you package a public custom metadata type, customers who install the package can add their own records to the metadata type. Your reusable functionality reads your custom metadata and uses it to produce customized application behavior. For example, you can use custom metadata types for the following.
创建公共自定义元数据类型后,您或其他人可以以声明方式创建由该类型定义的自定义元数据记录。在打包公共自定义元数据类型时,安装该包的客户可以将自己的记录添加到元数据类型中。您的可重用功能读取您的自定义元数据并使用它来生成自定义应用程序行为。例如,可以为以下内容使用自定义元数据类型。
Custom metadata rows resemble custom object rows in structure. You create, edit, and delete custom metadata rows in Metadata API or in Setup. Because the records are metadata, you can migrate them using packages or Metadata API tools.
自定义元数据行在结构上类似于自定义对象行。可以在 Metadata API 或安装程序中创建、编辑和删除自定义元数据行。因为记录是元数据,所以可以使用包或 Metadata API 工具迁移它们。
Usage Calculation
不限制个数,限制总长度为1000W个字符。
10 million characters
.255 characters
per long text area field for a given type) are included in the usage calculation.15 characters
in the usage calculation if their target is another custom metadata type, or 10 characters
if the target is Entity Definition or Field Definition.10 characters
.Create Custom Metadata Type
创建Custom Metadata Type
创建完成
API参照名为:Account_Setting__mdt
,__mdt
,自定义Object为__c
,Big Object为__b
,Externl Object为__x
.
使用方法:
// 就像普通的自定义Object一样,SOQL查询然后遍历取自己需要的值
List<Account_Setting__mdt> asm = [SELECT
Id, DeveloperName, MasterLabel, Language, NamespacePrefix, Label, QualifiedApiName
FROM Account_Setting__mdt];
for(Account_Setting__mdt tmp : asm){
if(‘COMPANY_CODE‘.equals(tmp.DeveloperName)){
System.debug(‘COMPANY_CODE:‘+tmp.MasterLabel); // WZJ
}
}
SFDC CustomLabels vs. CustomMetadata
原文:https://www.cnblogs.com/paynev/p/14757276.html