ABSYZ ABSYZ

  • Home

    Home

  • About us

    Who We Are

  • Our Expertise

    What we Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

Utilization of Hierarchy custom settings in formula field, custom button, process builder or workflow rules without hard-coding

Home / Article & Blogs / Custom Setting / Utilization of Hierarchy custom settings in formula field, custom button, process builder or workflow rules without hard-coding
By Monicaa Balaji inCustom Setting, Salesforce

Custom settings

Custom settings are similar to custom objects. Developers can create custom sets of data and associate custom data for an organization, profile, or specific user. All custom settings data is exposed in the application cache, which enables efficient access without the cost of repeated queries to the database. Formula fields, validation rules, flows, Apex, and the SOAP API can then use this data. The most important thing about Custom Setting is, it does not uses our salesforce data storage and resides in the” application cache”.

 

Types of custom settings

1)List Custom Setting
2)Hierarchy Custom Settings

List Custom Setting:
It provides a reusable set of static data that can be accessed across your organization. If we are using some set of data frequently within our application, putting that data in a list custom setting streamlines access to it. Data in list settings does not vary with profile or user but is available organization-wide(Static data).

Note: To enable the List custom setting we have to first enable them in the schema settings(Setup–>Schema settings).
Example: Storing Zip codes of all the areas with respect to a particular city.

 

Dataset name
Zip Code Field value
Florence
90001
Watts
90002
South Central
90003

 

Hierarchy Custom Setting

It uses a built-in hierarchical logic that lets you “personalize” settings for specific profiles or users. The hierarchy logic checks the organization, profile, and user settings for the current user and returns the most specific, or “lowest,” value. Instead of hardcoding the values we can define them for each of the levels and maintain the data accordingly.

As with list custom settings, when you create a new hierarchy custom setting, the platform creates a custom object in the background for you (notice the API Name field). You then add additional fields to the custom setting in the same manner that you do for custom objects (you are limited to checkbox, currency, date, date/time, email, number, percent, phone, text, text area, and URL fields).

Example: We might set up an org-wide custom setting of a 5% discount that everyone is authorized to offer. If we have a high-producing sales people that are in their own profile and are able to offer a 10% discount,also if there is one salesperson in that same profile that has lobbied the VP of Sales to be able to offer a 20% discount then with the hierarchy custom settings one can be able to manage all of the scenarios.

How does it work?
1)User level———>2)profile level——–>3)Organization level.
If the user level value is defined, then it will take the value defined for that particular user else it will take if the profile level value is defined.If the logged in user does not have any value defined at the user level or profile level, therefore Organization level value would be considered.

The following generic syntax can be used to access Hierarchy Custom Settings in formula field, Validation Rule, Workflow, Process builder and VF page.

Syntax: $Setup.CustomSettingName__c.FieldName__c

 

Steps to create  Hierarchy custom settings:-

Step-1: Navigate to Setup | Custom Settings | New.

 

Step-2: Click on new and create a custom setting object specifying the label, object name, setting type and visibility.

 

Step-3: Create a custom field for the object created, specifying the data type and the label for it.

 

Step-4: Click on “manage” for setting the values based on the levels(user or profile).Specify the values accordingly for the user level and the profile level.

 

 

 

Step-5: Click on the new button to set the organization default value.

 

 

 

 

How to access these values in Formula field, Workflow, Process builder ?

Using Hierarchy custom setting in formula field:

 

Using Hierarchy custom setting in Workflow Action -Field Update:

 

Process builder:

 

Using Hierarchy custom setting in Custom Button:

 

 

JavaScript  used in custom button: alert("Your Discount is:"+{!$Setup.Discount__c.Percentage_Allowed__c * 100}+"%")

 

Can we query the fields of the custom setting object?

The answer is “Yes”.
Query syntax: Select id,name,field_custobjField__c from Custom_settingObj__c
Ex: Select id,name,Percentage_Allowed__c from discount__c

 

 

 

 

How to get the hierarchy custom setting value in apex?

The answer is by using the “Custom settings methods ”.
Custom settings methods are all instance methods, that is, they are called by and operate on a particular instance of a custom setting.
In our Example, we have an object with API name as “Discount__c” and field name as “Percentage_Allowed__c”.

To get the org default value in Apex:
Discount__c d =  Discount__c.getOrgDefaults();
decimal discountValue= d.Percentage_Allowed__c;
system.debug(‘value is’ +discountValue);

To get the Specified profile  value in Apex :
string pid=’0056F000008ujg9QAA’;
Discount__c d =Discount__c.getInstance(pid);
decimal discountValue= d.Percentage_Allowed__c;
system.debug(‘value is ‘+discountValue);

To get the current profile’s value in Apex :
Discount__c d =Discount__c.getInstance(UserInfo.getProfileId());
decimal discountValue= d.Percentage_Allowed__c;
system.debug(‘value is’ +discountValue);

To get the User specified value
in Apex :
string pid=’00e6F000002zYfJQAU’;
Discount__c d =  Discount__c.getInstance(pid);
decimal discountValue= d.Percentage_Allowed__c;
system.debug(‘value is’ +discountValue);

To get the  Current User’s value in Apex :
Discount__c d =  Discount__c.getInstance(UserInfo.getUserId());
getInstance(UserInfo.getProfileId());
decimal discountValue= d.Percentage_Allowed__c;
system.debug(‘value is’ +discountValue);

 

 

 

Hierarchy Custom SettingSFDC
80
Like this post
1 Post
Monicaa Balaji

Search Posts

Archives

Categories

Recent posts

Meet OmniStudio – Revolutionize Your Creative Work

Meet OmniStudio – Revolutionize Your Creative Work

BioAsia 2023 in Hyderabad: An Annual International Event

BioAsia 2023 in Hyderabad: An Annual International Event

The Role Of Marketing in Small & Medium Enterprises

The Role Of Marketing in Small & Medium Enterprises

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Salesforce For Retail: How Salesforce CRM Can Help Retailers

What is ChatGPT & How Does It Work?

What is ChatGPT & How Does It Work?

  • Previous PostBlockchain for Salesforce
  • Next PostSwiftUI Framework

Related Posts

Meet OmniStudio – Revolutionize Your Creative Work
Salesforce

Meet OmniStudio – Revolutionize Your Creative Work

Salesforce For Retail: How Salesforce CRM Can Help Retailers
Salesforce

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Introduction To Copado Devops Tool
Salesforce

Introduction To Copado Devops Tool

What is Salesforce Code Builder?
Salesforce

What is Salesforce Code Builder?

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo

INDIA | USA | UAE

  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

Copyright ©2022 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT