Metadata
Apex Custom Settings
Using Custom Settings
Apex custom settings manage app settings with hierarchy.
Understanding Apex Custom Settings
Custom settings in Salesforce are similar to custom objects. They allow you to create custom sets of data and associate them with an organization, profile, or specific user. Apex custom settings are used to manage configuration data that is often required across your Salesforce application. This data can be easily accessed from your Apex code, reducing the need to hard-code values.
Types of Custom Settings
There are two types of custom settings in Salesforce:
- List Custom Settings: These are similar to a custom object. They allow you to store data that is accessible across your organization.
- Hierarchy Custom Settings: These are used to provide settings for different levels within the organization, such as for a specific user or profile, allowing a hierarchical structure for settings.
Creating Custom Settings
To create a custom setting, follow these steps:
- Navigate to Setup in Salesforce.
- In the Quick Find box, enter Custom Settings.
- Click New to create a new custom setting.
- Select the type (List or Hierarchy), then fill in the required information.
Accessing Custom Settings in Apex
Once you have created a custom setting, you can access its data in Apex using SOQL or the custom setting methods. Here is how you can do it:
Best Practices for Custom Settings
When working with custom settings, consider the following best practices:
- Use custom settings to avoid hard-coding configuration data within your Apex code.
- Take advantage of hierarchy custom settings to customize user experiences based on individual profiles or users.
- Keep your custom settings organized and document their purpose clearly.
Metadata
- Custom Metadata
- Custom Settings
- Previous
- Custom Metadata
- Next
- Apex Sharing