+ Start a Discussion
Manogna Kovi 9Manogna Kovi 9 

Please provide any realtime scenarios for custom settings

AbhinavAbhinav (Salesforce Developers) 
Hi Manogna,

Basically when we need data that is required frequently  or mutiple times in a transaction we go for Custom setting or Custom metadata.

What is a Custom Setting?
Custom settings are similar to custom objects. We have to create our own custom setting similar to creating a custom object.).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. The custom setting data can then be used by formula fields, validation rules, flows, Apex, and the SOAP API.

Why do We Need Custom Settings?
Apex runs in a multitenant environment, the Apex runtime engine strictly enforces limits to ensure that runaway Apex code or processes don’t monopolize shared resources. If some Apex code exceeds the limit then exception cannot be handled. When we need data we query from object and display, if we query multiple time there is chance of hitting governing limit. So to avoid governing limit we use custom setting. It allows us to store a set of data and access it without querying it from the apex.  


Real time scenario  for:

1. List Custom Settings:
  eg :  When you want store some data that is sort of universal for everyone irrespective of profile or user who are accessing  it. Let say you are  storing pincode of every city. You will go for list custom settings.

2 . Hierarchy Custom Settings

eg: Supposse you want to give discount to user on online shopping site during a sale depending  on whether they are a premium  member or Non premium member. i.e you are changing discounts percentage based on user( in salesforce term based on profile ). you will go for Hierarchical custom settings.

I hope this example will help you understand .

If it helps mark it s best answer.