Skip to main content

Custom Settings in Salesforce

"Custom Settings are hidden gems in Apex that always impresses people, especially bosses!" but the next question that stands is "How?"
As shared by David Liu in his site sfdc99.com

Consider a block of code that is executing and sending out different results for different input types but those inputs are not managed within the code. Its managed outside, by someone else. Being a developer, your task is reduced as all you have to do is to enable your code to understand those external values from some external object and use them for different outputs.

Custom settings are very useful when it comes to storing static or reusable information in Salesforce, plus it also can work as a switch to turn your application rules ON and OFF. Very basically speaking, Custom Settings are much like Custom Objects and are accessible via their own API, but you can’t have triggers on a Custom Setting and the available field types are more limited. They do count towards your Custom Objects governor limit however. So comes the next obvious question. Why should we use em? Custom Settings are stored in the application cache and do not count against SOQL limits when fetched. Also they are much quicker to implement, easier to maintain and they won’t use up one of your precious Custom Tab limits to maintain. They can also only be updated by a System Administrator (or Configure Application profile permission user). Custom Settings have their own methods to access them – we will have a look below at an example on how we can use getInstance() and getAll() methods.
More reasons are mentioned below:
* To hold environment ids
* Use it as a switch for Apex Triggers, validation rules to turn on or off.
* Providing dynamic overrides in the VF pages
* Switching VF components on/off like "Show details checkbox" or "Show history checkbox" and these details would be remembered as we can run CS depending on Org,profile pr user level.

The formal conversation now:
Types of Custom Settings? List and Hierarchical.
Difference? Data in List settings do not vary by user and profile, there is no ownership, field level security or record security, and it is available organisation wide (i.e. public for all).
Example to use a custom setting in the validatuion rule:
AND(NOT($Setup.Opportunity_Web__c.Exclude_Marketing_for_Web__c)

Opportunity_Web__c --> Custom Setting Name
Exclude_Marketing_for_Web__c --> Field in Custom setting

NOTE: Only Hierarchical custom settings can be used as a part of the validation rules/formula fields.

References:
sfdc99.com - David Liu
http://makepositive.com/Salesforce-custom-settings
http://www.verticalcoder.com/2012/07/26/custom-settings/

Comments

Popular posts from this blog

Bulk assign permission set with Data-Loader

Many times, we come across scenarios where we need to assign all the users in a "Public Group" with a specific "Permission Set". Looks like a genuine & monotonous problem right? Well, yes it is right as you need to add the users one-by-one or by using the great app-exchange product "The Permissioner". What can be irritating is, when there are different users whose usernames are starting with different letters and suddenly the app crashes. Frustrating AF.!!!!!!!! To put an end to this problem, let me share with you a simple technique that can actually take away all the nightmares of such problems from you. "Data-Loader" - A very simple, yet very powerful tool that is actually what your savior is. Wanna know more about 'HOW'? Read On!!! Let us assume, the group whose users you would like to assign a specific permission set to be "My Group" with the ID "00G0O000001fMc0UAE" The permission set that we want to ...

Custom Metadata Types

Metadata is something that defines the overall organizational structure. And then if you can create your own,custom types as per your requirements, how good that would be? Hell yeah.!! Post summer 15, you can create your own metadata in Salesforce.  AWESOME.!!!! Custom metadata is customizable, deployable, packageable, and upgradeable application metadata. A custom metadata type is defined as a custom object and is stored in the objects folder. Custom metadata types have a suffix of __mdt (instead of __c for custom objects). Custom metadata type field names have a suffix of __c, like other custom fields. Custom metadata type field names must be dot-qualified with the name of the custom metadata type to which they belong. (SOURCE: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_custommetadatatypes.htm) The records of custom metadata types are metadata This means that, unlike custom objects or custom settings records, the records of custo...

Salesforce Reports & Dashboard

Reports  - The very basics of any business needs which gives a great view about ones organizational status. Be it your sales pipeline, your service queue or marketing insights, one look at a report and you have it all. Sounds amazing isn't it? All the hard work you do, all the tough escalations you manage to handle, all the happy customers or all the dissatisfied customers, everything is represented in numbers and is displayed in graphical form using dashboard or reporting snapshot. Salesforce being a Customer Success Platform has one robust reporting engine which helps us build different insights about how an organization is performing.  In Salesforce we have different tools designed specifically according to your needs. Requirements that are must for your business to grow.  Whatever you do, its all numbers and graphs. :)  Essentially there are 4 types of reports available for use: Tabular Report--  A basic table formatted report showing...