Pages

Monday, November 11, 2013

Salesforce Custom Setting

Although Custom Setting is similar with Custom Object, but they are very different and totally for different usage. Custom object used to store all data within Salesforce for any transactions, it works similar with standard object, such as: Account, Contact, Opportunity, etc and you can create custom tab for that object.

While Custom Setting used to store application configurations, such as: value based on each application type or user. You cannot put show custom setting value directly as a custom tab. But, to access custom setting data, you need to access it from: Formula fields, Validation rules, Workflow rules, Apex class, and API.

There are 2 type of custom setting: List and Hierarchy. Formula field, Validation rule and Workflow rule only can access Hierarchy type custom setting, while Apex and API can access both. Once you select the type, you will not able to change it.

If the custom setting is a list, you can add set of data. For example, if your application had a setting for country codes, each set might include the country's name and dialing code.

If the custom setting is a hierarchy, you can add data for the user, profile, or organization level. For example, you may want different values to display depending on whether a specific user login to system, or a specific profile, or for general users.

To access hierarchy Custom Setting from formula field, workflow rule or validation rule:
{!$Setup.CustomSettingName__c.CustomFieldName__c}

Use case: all users have to select Account Active status, except System Administrator.

Here is the step to use Custom Setting in Validation Rule:
1. Create Custom Setting:  Setup | Develop | Custom Settings
2. Create Fields in Custom Settings

3. Manage Custom Settings
Enter Default Organization Level Value, you can skip the value for User or Profile level.

4. Modify Validation Rule
($User.ProfileId <> $Setup.Rules_Id__c.Exception_Id__c) && ISBLANK(TEXT(Active__c))

Checkout this blog for step-by-step to configure Custom Setting.


To access Custom Setting from API:
SELECT Id, Name, Exception_Id__c, Name__c FROM Rules_Id__c
This is very similar with SOQL query to custom object, isn't it?


Limitation of Custom Setting:
  • Maximum total data of 10 MB, but if you have less than 10 license users, multiply 1 MB with number of users
  • 300 fields per custom setting.
  • Can’t share a custom setting record.
  • No owner assigned for each custom setting record
  • Each custom setting counts against the total number of custom objects available for your organization.

You can access Custom Setting field through SOAP API, run SOQL to get the values, and it can be deployed using Change Set.

To deploy custom setting data/value, you can use Data Loader, see this blog.


Reference:



No comments:

Post a Comment