Loading
Extend Salesforce with Clicks, Not Code
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Access Custom Settings with Code

          Access Custom Settings with Code

          You can access custom settings from Apex, SOAP API, and formulas.

          Required Editions

          Available in: Salesforce Classic and Lightning Experience.

          Available in: Group, Professional, Developer, Enterprise, Performance, Unlimited, and Database.com Editions.

          Packages aren’t available in Database.com.

          Note
          Note Formulas include: flows, workflow rules, approval processes, validation rules, formula fields, and Process Builder processes.

          Here are some sample code segments:

          Formula Fields
          Formula fields only work for hierarchy custom settings; they can’t be used for list custom settings.
          {!$Setup.CustomSettingName__c.CustomFieldName__c}
          Apex
          Apex can access both custom setting types.
          Samples for List Custom Settings
          When you add data to a custom setting, name each data set so that you can distinguish them. The following returns a map of custom settings data. The getAll method returns values for all custom fields associated with the list setting.
          Map<String_dataset_name, CustomSettingName__c> mcs = CustomSettingName__c.getAll();
          The following example uses the getValues method to return all the field values associated with the specified data set. This method can be used with list and hierarchy custom settings, using different parameters.
          CustomSettingName__c mc = CustomSettingName__c.getValues(data_set_name);
          Samples for Hierarchy Custom Settings
          The following example uses the getOrgDefaults method to return the data set values for the organization level:
          CustomSettingName__c mc = CustomSettingName__c.getOrgDefaults();
          

          The following example uses the getInstance method to return the data set values for the specified profile. The getInstance method can also be used with a user ID.

          CustomSettingName__c mc = CustomSettingName__c.getInstance(Profile_ID);
          SOAP API
          Custom settings that have Privacy defined as Public have the same type of exposure to the API as custom objects. When a custom setting is contained in a managed package, and Privacy for a custom setting is Protected, the settings can only be accessed by the Apex code or formulas that are part of the managed package.
          Note
          Note You can also access custom settings data through a Standard Object Query Language (SOQL) query, but this method doesn't use the application cache. It’s similar to querying a custom object.
           
          Loading
          Salesforce Help | Article