General

Using Custom Settings in Salesforce

Salesforce provides a powerful set of tools for managing your data and settings, but there may be times when you need to go beyond what’s provided in the standard Salesforce interface. In those cases, you can create custom settings—which are similar to custom objects—to store information specific to your organization, application, or user.

There are two types of custom settings: list and hierarchy. List settings let you access large sets of static data in your organization by using a built-in caching mechanism. Hierarchy settings enable you to tailor information for specific users or profiles within your organization by providing different values for different users.

This article describes how to create and use both types of custom settings.

Creating Custom Settings:

To create a custom setting, follow these steps:

  • From Setup, enter Custom Settings in the Quick Find box, and then select Custom Settings.
  • Click New in the Custom Settings List section.
  • Enter a Label and Name for your custom setting. The Name is used to reference the custom setting in Apex code.
  • Optionally, enter a description of your custom setting.
  • Select the visibility for your custom setting: Protected or Public. Protected settings can only be accessed by Apex code that uses the with sharing or without sharing keywords or by system context such as triggers. Public settings are accessible to all users and from client applications such as Visualforce pages and Lightning Components.
  • In the Category list, select the type of custom setting you want to create: Hierarchy or List.
  • If you selected Hierarchy, enter a description of the setting and select the checkbox next to Show this custom setting in the Lightning Setup UI. This setting is only available in API version 37.0 and later.
  • Click Save.
  • After you create a custom setting, you can add fields to it just like you would add fields to a custom object. The data type of each field must be one of the following: any primitive data type including auto number, checkbox, currency, date, date-time, email, encrypted text, id, integer, percent, phone, picklist (multi-select), picklist (single select), reference (lookup relationship), text area long or rich text area long, text area plain or rich text area plain, text area rich or rich text area long, URL, or picklist (multi-select).
  • You can add up to 1,000 fields to a custom setting.
  • When you finish adding fields, click Save.

Creating List Custom Settings:

To create a list custom setting:

  • From Setup, enter Custom Settings in the Quick Find box, and then select Custom Settings.
  • Click New in the Custom Settings List section.
  • Enter a Label and Name for your custom setting. The Name is used to reference the custom setting in Apex code. For example, this setting might be named MyOrgSettings__c.
  • Optionally, enter a description of your custom setting.
  • In the Category list, select List.
  • Select the visibility for your custom setting: Protected or Public. Protected settings can only be accessed by Apex code that uses the with sharing or without sharing keywords or by system context such as triggers. Public settings are accessible to all users and from client applications such as Visualforce pages and Lightning Components.
  • Click Save.
  • After you create a custom setting, you can add fields to it just like you would add fields to a custom object. The data type of each field must be one of the following: any primitive data type including auto number, checkbox, currency, date, date-time, email, encrypted text, id, integer, percent, phone, picklist (multi-select), picklist (single select), reference (lookup relationship), text area long or rich text area long, text area plain or rich text area plain, text area rich or rich text area long, URL, or picklist (multi-select).
  • You can add up to 1,000 fields to a custom setting.
  • When you finish adding fields, click Save.

Conclusion:

Custom settings are a great way to store data that you need to access in your Apex code. There are two types of custom settings, hierarchy and list. Hierarchy settings allow you to specify different values for different users while list settings provide a single set of values that is available to all users. Custom settings are easy to create and use and can be a valuable addition to your toolkit.

Admin

Kids’ world is filled with infinite fun! Celebrate your life with lots of fun, informative, educational and inspirational data with KidsWorldFun!

Recent Posts

How To Advertise Your Home Business Effectively

Venturing into a home-based business realm offers a unique blend of freedom and challenges, particularly… Read More

12 hours ago

Cavernous Preparations: Your Go-To Packing Checklist for Wieliczka Salt Mine

Welcome to the underground wonder that is the Wieliczka Salt Mine! As you gear up… Read More

18 hours ago

10 Tips for Planning a Fun Vacation for Your Kids

Planning a family vacation can be an exciting and fun experience for everyone involved, especially… Read More

20 hours ago

Responding To a Personal Injury Lawsuit: Do You Know Your Legal Rights?

Being involved in a car accident can leave you shaken up and lost about what… Read More

23 hours ago

5 Reasons Why Montessori Shelves Are Essential for Kid’s Development

Wondering if investing in a Montessori shelf for your child is worthwhile? It is. Looking… Read More

2 days ago

The Benefits of Tutoring in Spanish for Students of All Ages

If you're thinking about honing your Spanish language abilities, tutoring may be the first step… Read More

2 days ago