Custom Settings #inSalesforce

Custom Settings #inSalesforce

This is to create and manage custom data at the organization, profile, and user levels. Custom settings data is stored in the application cache. 

This means you can access it efficiently, without the cost of repeated queries.

Custom settings data can be used by formula fields, Visualforce, Apex, and the Web Services API.


Two types of custom settings:


  • List Custom Settings

-This provides a reusable set of static data that can be accessed across your organization.

-A List type defines application-level data, such as country codes, that is stored in the application cache

Use getAll method returns values for all custom fields associated with the list setting.

Map<String_dataset_name, CustomSettingName__c> mcs = CustomSettingName__c.getAll();

e.g., CustomSettingName__c mc = CustomSettingName__c.getValues(data_set_name);


  • Hierarchy Custom Settings

-This uses a built-in hierarchical logic that lets you "personalize" settings for specific profiles or users.

-A Hierarchy type defines personalization settings, such as default field values, that can be overridden at the organization, profile, or user level.

Use getOrgDefaults method to return the data set values for the organization level.

CustomSettingName__c mc = CustomSettingName__c.getOrgDefaults();

e.g., CustomSettingName__c mc = CustomSettingName__c.getInstance(Profile_ID);



Reference: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_customsettings.htm


Comments