---
schema_version: "1"
id: d140f0dd74e6db24cb24df4e8e320819ae6e7ebca0898ceb0aa4bffab6eae45d
title: Access Custom Settings with Code
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/cs_accessing.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.cs_accessing.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: c83ccaf31f128609bfc3fcaf314bbff4bd839945186da50e608adf02236fa803
description: You can access custom settings from Apex, SOAP API, and formulas.
products:
  - Salesforce Platform
  - Security
release: "264"
---
# Access Custom Settings with Code

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

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition">
        <colgroup>
          <col>
        </colgroup>
        <tbody>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">Available in: Salesforce Classic and Lightning Experience.</td>

          </tr>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">
              <p>Available in: <strong>Group</strong>, <strong>Professional</strong>, <strong>Developer</strong>, <strong>Enterprise</strong>,
                <strong>Performance</strong>, <strong>Unlimited</strong>, and <strong>Database.com</strong> Editions.
              </p>
              <p style="margin-bottom:0;">Packages aren’t
                available in <strong>Database.com</strong>.</p>
            </td>

          </tr>
        </tbody>
      </table>

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_click-264-0-0-production-enus/5f7d9219-b7b1-4552-8891-f1aba9b289fc/images/icon_note.png)

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](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_click-264-0-0-production-enus/5f7d9219-b7b1-4552-8891-f1aba9b289fc/images/icon_note.png)

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.

#### See Also

- [Grant Permissions on Custom Settings](https://help.salesforce.com/s/articleView?id=platform.cs_grant_permission.htm&release=264.0.0&type=5 "By default, access to custom settings is limited through the Restrict access to custom settings org-wide preference. Admins can grant API Read access through profiles and permission sets to users without the Customize Application permission.")