sfdcamplified ebooks

Skip to content
  • Home
  • Blogs
  • LWC Comic Book
  • Lightning Web Component
  • Write For Me
  • About Me
  • Newsletter
MENU
  • Home
  • Blogs
  • LWC Comic Book
  • Lightning Web Component
  • Write For Me
  • About Me
  • Newsletter

Custom settings: List and Hierarchy custom settings

Smriti Sharan    December 4, 2018 April 12, 2019    Comments Off on Custom settings: List and Hierarchy custom settings

Custom settings are similar to custom objects and enable application developers to create custom sets of data, as well as create and associate custom data for an organization, profile, or specific user. All custom settings data is exposed in the application cache. 

Benefits of Using Custom Setting:

  • Custom settings data is exposed in the application cache, which enables efficient access without the cost of repeated queries to the database.
  • Custom settings data can be used by formula fields,validation rules, Visualforce, Apex, workflow rules, approval processes, custom button and the Force.com Web Services API.
  • You can make visibility of custom setting public or protected.
  • They  do not count against SOQL limits when fetched

Types Of Custom Settings

There are two types of custom settings:

  • List Custom Settings A type of custom setting that allow you to store org-wide static data that is frequently used.This custom setting is equivalent to custom / standard object. We can store values in tabular format.
  • Hierarchy Custom Settings A type of custom setting that uses a built-in hierarchical logic that checks the organisation, profile, and user settings for the current user and returns the most specific, or “lowest,” value. 
  • You can only access hierarchy custom settings in formula field and validation rules.
  • Most unique feature about Hierarchy custom setting is that we can have different values at Organization level, profile level and user level.
  • Custom setting can be used in formula fields using global variable $Setup. Syntax to use custom setting is {!$Setup.CustomSettingName__c.CustomFieldName__c}
  • Highest priority is given to value defined at user level then profile and at last organization level.
  • Once created these settings can be used even in formula fields or normally in APEX code to store information 
 

You Can enable list custom setting schema Setting Page

Setup > schema Setting Page > List custom Setting

 

Create List Custom Setting

 


Add field Currency to custom settings

Select Manage to add data to the field


Below is the list of data I added in Currency_c Field

Methods of custom setting

  • getAll()
    Returns a map of the data sets defined for the custom setting.
  • getInstance(dataSetName)
    Returns the custom setting data set record for the specified data set name. This method returns the exact same object as getValues(dataSetName).
  • getValues(dataSetName)
    Returns the custom setting data set record for the specified data set name. This method returns the exact same object as getInstance(dataSetName).
 

getAll()

List<Country_Currency__c> cc = Country_Currency__c.getall().values();

system.debug(cc);

 
 

getInstance(dataSetName)

Country_Currency__c cc = Country_Currency__c.getInstance(‘India’);

system.debug(cc);

Map<string,Country_Currency__c> mapCurrency = Country_Currency__c.getAll();

// display the currency for India

System.debug(‘Currency: ‘+mapCurrency.get(‘India’).Currency__c);

getValues(dataSetName)

Country_Currency__c myCS1 = Country_Currency__c.getValues(‘United States’);

String myCCVal = myCS1.Currency__c;

Country_Currency__c myCS2 = Country_Currency__c.getInstance(‘United States’);

String myCCInst = myCS2.Currency__c;

system.debug(myCCVal); 

system.debug(myCS2); 

system.assertEquals(myCCinst, myCCVal);

Hierarchy Custom Settings

We can create custom fields in custom settings and store data in them

We can create custom fields in custom settings and store data in them

After you define your custom settings and add fields, you need to populate the fields with data.

 

Reference

https://blog.jeffdouglas.com/2010/01/07/using-list-custom-settings-in-salesforce-com/

https://www.jitendrazaa.com/blog/salesforce/use-hierarchy-custom-settings-to-avoid-hard-coding-in-formula-field-custom-button-process-builder-or-workflow-rules/

 

 



Did you enjoy this article?
Signup today and receive free updates straight in your inbox.
Thank you for subscribing.
Something went wrong.
I agree to have my personal information transfered to MailChimp ( more information )
0Like
0Dislike
50% LikesVS
50% Dislikes
salesforce    custom metadata, custom setting, getall, getinstance, getvalue, hierachial, list, salesforcedeveloper, sfdc

Post navigation

Create local WordPress site using XAMPP
Salesforce interview with Fiverr

Quote of the Day

more Quotes

TRAILMIXES FOR BEGINNERS,ADMIN AND LWC LOVERS

 

TOP SALESFORCE EXPERT

 

RANKED IN THE BEST SALESFORCE DEVELOPER BLOGS LIST!

Subscribe to the Blog

Name


Follow Us

  • 5likes
  • 6followers
  • 8490subscribers
  • 71followers

Recent Posts

  • Salesforce CPQ Interview Questions and Answers with Screenshots in Every Step
  • Salesforce CPQ Interview Questions Day 1
  • 177 interview questions covering every aspect of Salesforce CPQ
  • Salesforce CPQ: Filter Product Rule Hands-On Workbook
  • Salesforce CPQ: Selection Product Rule with Domino’s Pizza Hands-On Workbook
Theme Salinger by GalussoThemes | Powered by WordPress
WhatsApp chat