Custom Setting vs Custom Metadata Types

Custom Settings分为List和Hierarchy两种类型,用于创建定制数据集,适用于组织、配置文件或特定用户。List Custom Settings提供静态数据,Hierarchy Custom Settings实现层次逻辑。Custom Settings的数据在应用缓存中,访问高效。它们不支持关系字段,且一旦创建类型不可更改。迁移时只部署元数据,需手动上传数据。在Apex中可进行CUD操作,但Test Class中需要SeeAllData注解。与之相比,Custom Metadata Types被视为元数据,具有更多选项,如字段类型、布局和验证规则,支持元数据关系,并且在Apex中不允许CUD操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Custom Setting有两种类型:

1.List Custom Settings:用于创建一组静态的数据;

2.Hierarchy Custom Settings:通过指定的Profile或者用户设置指定的数据。

 

Custom Settings :

“Manage List Custom Settings Type” is disabled, to allow the creation of List Custom Settings you have to enable “Manage List Custom Settings Type”.

To enable it : Go to Setup | Data or Search “Schema Settings” in Quick Find | Click Schema Settings | Enable “Manage List Custom Settings Type

  • Custom settings enable you to create custom sets of data, as well as create and associate custom data for an organization, profile, or specific user. All custom settings data is exposed in the application cache, which enables efficient access without the cost of repeated queries to the database.
  • You can control the visibility of custom setting by specifying it as public or protected. If custom setting is marked as protected, the subscriber organization will not be able to access the custom setting. If it is marked as public, then subscriber org can also access it.
  • There are 2 types of custom setting, List and Hierarchy. Once you create custom setting, then you cannot change the type (List to hierarchy or vice versa).
  • List custom setting provides a reusable set of static data that can be accessed across your organization to all user.
  • Hierarchy custom setting uses a built-in hierarchical logic that lets you “personalize” settings for specific profiles or users. In Hierarchy custom setting for logged in user, system first check user then profile and then org wide setting in order to return data from hierarchy custom setting.
  • Custom settings do not support relationship fields.
  • Custom Settings have the same permission to edit the records and to edit the configuration. Both can be done with the “Configure Application” permission.
  • You can access custom setting data using instance methods and can avoid SOQL queries to database.
  • While migrating custom setting to another org, It only deploys the metadata, you need to upload data into the custom setting post deployment.
  • Custom setting can be used by formula fields, validation rules, flows, Apex, and the SOAP API.
  • You cannot access List custom setting in Validation rule. Only Hierarchy custom setting can be used.
  • You can perform CUD (Create, Update, Delete) operation on custom setting in apex.
  • Custom settings are not visible in test class without “SeeAllData” annotation.

Custom Metadata Types :

  • Custom metadata are like custom setting but records in custom metadata type considered as metadata rather than data. These are typically used to define application configurations that need to be migrated from one environment to another, or packaged and installed.
  • Custom Metadata Types have WAY more options that Custom Settings, like picklist fields, long text areas (in Spring ’17), page layouts, and validation rules.
  • You can control the visibility of Custom Metadata Types by specifying it as public or protected. If it is marked as public type, then anyone can see it. If it is marked as protected type, in the installed managed package subscriber organization, only Apex code in that managed package can use it.
  • You can create lookups between Custom Metadata objects.
  • Metadata Relationship provides the ability to add relationships from your custom metadata to other things in your app, such as other custom metadata, custom or standard objects and fields, and static resources.
  • In Custom Metadata, you can edit the records with “Configure Application” permission, but you require “Author Apex” to edit the configuration.
  • With custom metadata types, you can issue unlimited Salesforce Object Query Language (SOQL) queries for each Apex transaction.
  • While migrating Custom Metadata Types to another org, the associated data you created against it is also deployed to the target organization.
  • You cannot perform CUD (Create, Update, Delete) operation on custom metadata type in apex.
  • You can control the visibility of custom metadata type while adding it in package.
  • Custom metadata type are visible in test class without “SeeAllData” annotation
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值