Custom Settings :
Custom settings are similar to custom objects. Application developers can create custom sets of data 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. Formula fields, validation rules, flows, Apex, and SOAP API can then use this data.
There are two types of custom settings.
1.List Custom Settings : A type of custom setting that provides a reusable set of static data that can be accessed across your organization.( Same data for every user in organization).
Map<String_dataset_name, CustomSettingName__c> mcs = CustomSettingName__c.getAll();
CustomSettingName__c mc = CustomSettingName__c.getValues(data_set_name);
The getAll method returns values for all custom fields associated with the list setting.
2.Hierarchy Custom Settings :The hierarchy logic checks the organization, profile, and user settings for the current user and returns the most specific, or “lowest,” value.( Data can be fectched based on profile, user).
CustomSettingName__c mc = CustomSettingName__c.getOrgDefaults();
CustomSettingName__c mc = CustomSettingName__c.getInstance(Profile_ID);
Here,the getOrgDefaults method to return the data set values for the organization level.
Here,the getInstance method to return the data set values for the specified profile.
Pros of Custom Setting:
1. No query required.
2. Fast access of data increasing performance.
3. Hierarchical custom setting allows different data for different profile/users.
Cons of Custom Setting :
1. Custom Setting can not be deployed.
2. only 300 field allowed.
3.Tab not created in custom setting.
4. Custom setting do not support relationship field.
Custom Metadata :
Custom metadata type in salesforce is customizable, deployable, packageable, and upgradeable application metadata. Custom metadata types are mainly used for app configuration. Custom Metadata Types are similar to Custom Settings in Salesforce, except that they are deployable and packagable.
It always needs to query custom metadata to get records. Even though you query on metadata,it will not count with governor limits.
SELECT ID, Custom_Value__c, Phone__c, Actual_Value__r.MasterLabel, Value_Rating__c, DeveloperName FROM Actual_Value_Setting__mdt
When you create custom metadata, custom metadata API ends with ”__mdt”
No comments:
Post a Comment