Govur University Logo
--> --> --> -->
...

When and how would you implement custom settings versus custom metadata types, highlighting their specific capabilities and limitations?



Choosing between custom settings and custom metadata types in Salesforce depends heavily on the nature of the data you need to store and how that data will be used. Both offer ways to store configuration information, but they have distinct characteristics and are suited for different use cases, with specific capabilities and limitations that influence the decision-making process. Custom settings are designed to store application data that may change over time, or is specific to a user or a profile. They behave very much like custom objects, but with the added benefit of being cached, providing faster access to data. They are ideal for storing configuration data that needs to be easily updated by administrators or users without requiring a code change. There are two types of custom settings: list custom settings and hierarchy custom settings. List custom settings provide an organization-wide set of values, whereas hierarchy custom settings provide data that is specific to a user, profile or organization. They also have a limit on the amount of data that can be stored. For example, suppose you have a requirement to store the currency conversion rates for different regions in your organization, and that rate is updated every month. In this case, a list custom setting is an excellent option as the values may change frequently and it's a straightforward way to store it and access it in Apex code or validation rules without the need to create a custom object and create SOQL queries. Another example would be to store email template IDs for sending notifications in Apex code. Also, you can use hierarchy custom settings to store profile or user specific data like the default language that should be used for the application or specific preferences. In this example, a user can select a specific language and that can be stored using a hierarchy custom setting.

Custom settings have the primary limitation that they can store a limited amount of data. If the data needs to be more complex or if there is a lot of data, custom settings may not be a good fit. Also, they are mainly used for application configuration and are not designed for storing data that needs to be tracked or is transactional. In addition, custom settings are not deployable using the metadata API unless they are marked as public, and can only be deployed using change sets. In most cases, custom settings cannot be used with data loader and if they need to be deployed across multiple sandboxes, you will need to copy them individually in each sandbox. Finally, custom settings are cached, which greatly improves performance and reduces the number of SOQL queries you have to write. However, if the data needs to be updated frequently, you need to be mindful of the cache refresh cycle.

Custom metadata types, on the other hand, are used for storing configuration data that rarely changes and is designed to be deployed between different Salesforce organizations. They are very similar to custom settings, but they are not intended to store large datasets. They are ideal for storing metadata that needs to be part of your deployment process. They are great for settings or rules that define how the application works. They are more akin to custom objects, but the main difference is that data is part of the metadata itself. For example, if you have an integration requirement and you want to store the integration end points, API keys, or other configuration details that need to be moved across environments, this would be a great use case for a custom metadata type. Another example would be if you want to store reusable rule definitions or conditions that can be referenced from multiple Apex classes, flows, or validation rules. Custom metadata records can also have picklist values, and all of this data is deployed and treated as code.

Custom metadata types have some notable limitations. You cannot access custom metadata using SOQL queries, as it is part of the metadata of the application, but you can use a special Apex class to query and access that data. Since data in custom metadata is treated as code, it has to be deployed from the sandbox to production. Custom metadata does not have the concept of caching like custom settings do. If you need to update custom metadata, you need to deploy the changes across environments. Therefore, custom metadata is designed for configuration data that does not change frequently. Also, custom metadata is typically used for technical configuration and not for data that is specific to user preferences or settings. Custom metadata, while it can be updated using Apex, is not designed to store transactional data that changes frequently and is user specific. If you need to store data that is specific to a user profile or user, then custom settings would be a much better option.

In summary, choose custom settings for data that needs to be modified frequently, is specific to the user or profile, and has a limited amount of data. Custom settings are good for configurations that can be updated by users directly and for configurations that need caching to speed up access to the data. Choose custom metadata types for configurations that are technical in nature and need to be deployed across different environments and are not typically modified by end users directly. Custom metadata is suitable for data that is part of the core application configuration and requires a more structured deployment approach. Consider your specific needs for data management and deployment requirements when deciding between custom settings and custom metadata types.