75 votes
Accepted

What is the difference between Custom Settings and Custom Metadata Types

I’m the original inventor of and lead developer for custom metadata types. Although we have a variety of use cases in mind, custom metadata types are primarily intended to let you develop peers of ...
user avatar
37 votes
Accepted

How to create Hierarchy custom settings in Apex

You can use either of the two following constructs: insert new custSettings__c(SetupOwnerId=UserInfo.getOrganizationId(), SomeField__c='Some Value'); Or: custSettings__c settings = custSettings__c....
user avatar
  • 438k
26 votes

What is the difference between Custom Settings and Custom Metadata Types

I came up with the below advantages (and disadvantage). I'd be interested if you see any other ones. Perhaps the biggest advantage Custom Metadata Types have over Custom Settings is that the data ...
user avatar
20 votes
Accepted

Eliminate query on Custom metadata type?

Edit: The rows themselves now count against the 50k SOQL row limit, although they do not count against the 100 SOQL query limit. To access custom metadata records without consuming SOQL rows is to use ...
user avatar
  • 438k
18 votes
Accepted

Custom setting Setting type not visible

You Can enable list custom setting schema Setting Page Setup > schema Setting Page > List custom Setting
user avatar
  • 630
15 votes
Accepted

How do I access Custom Settings in Apex?

You can access them just like you would a custom object, using SOQL. By doing that though, you aren't fully leveraging one the big advantages of using a custom setting over a custom object, no impact ...
user avatar
14 votes

What is the difference between Custom Settings and Custom Metadata Types

I've done quite a bit of research on Custom Metadata Types vs Custom Settings, and I've found that in only a few cases are Custom Settings more useful. Custom Metadata types have a number of ...
user avatar
  • 1,467
12 votes
Accepted

Retrieve custom setting value - apex

here you go : MyCustomSetting__c cs = MyCustomSetting__c.getInstance('Days'); // you then have access to cs.active__c and cs.age__c
user avatar
  • 63k
12 votes
Accepted

Giving users access to a specific custom setting without granting them Customize Application access

You can get around the need for a user to have the Customize Application permission if you proxy the custom setting object through another class or properties in your controller. If your VF page is ...
user avatar
12 votes
Accepted

Hierarchy Custom Setting .getInstance() Id

A few things to take into consideration: Are you accessing from a test method - If so you must insert a custom setting first Is there a record for the Specified "Instance" for the current context ...
user avatar
  • 53.2k
12 votes

Eliminate query on Custom metadata type?

Just An Update: Salesforce is coming up with new methods to retrieve custom metadata type records in a similar way custom setting records are retrieved. Yes, Without SOQL query. and It's happening in ...
user avatar
11 votes

custom setting getAll() versus SOQL

Summary - getAll() is >10x faster, but SOQL is still fast Based on my testing scenario, using custom settings instance methods offer ~40x performance improvement, in addition to the advantages of ...
user avatar
11 votes
Accepted

protected and public custom settings

There's no difference between public and protected custom settings in an unmanaged package scenario. Anyone with Customize Application can modify the values of the custom settings. For a managed ...
user avatar
  • 438k
11 votes
Accepted

Custom MetaData Types reference in Formula Field

Unfortunately, you can't reference custom metadata types in formulas at all. Their primary purpose is to provide metadata that's easy to package and transport between orgs, and primarily intended for ...
user avatar
  • 438k
10 votes
Accepted

Can you do a SOQL Query on a Hierarchical Custom Setting?

Technically, the custom setting is an object just like other custom objects. So you can do the following SOQL query: SELECT Id, Name FROM Your_Setting__c Where SetupOwnerId = :profileId FOR UPDATE ...
user avatar
9 votes
Accepted

Is encrypting passwords in protected custom settings a security requirement?

You don't need to encrypt the password if it is never visible to the user. Protected settings are impossible to access, even by administrators, outside of the code provided by the developer of the ...
user avatar
  • 438k
9 votes
Accepted

Activate and Deactivate trigger using Custom Setting

One Checkbox Custom Setting field should be sufficient to toggle between active and inactive states for the trigger. First thing in your trigger, check the hierarchy custom setting value and return ...
user avatar
9 votes

Where should we store username/password/endpoint…in Salesforce?

Better to use Named Credentials Named Credentials are a safe and secure way of storing authentication data for external services called from your apex code such as authentication tokens A named ...
user avatar
9 votes
Accepted

How to retrieve Custom Settings from Sandbox to a local SFDX Project?

They're the same as a CustomObject. You can retrieve one via the terminal: sfdx force:source:retrieve -m CustomObject:CustomSettingName__c In the Org Browser, they'll also be listed under Custom ...
user avatar
  • 438k
8 votes

How do I access Custom Settings in Apex?

While there is already a great answer, I would like to point out that in a VisualForce Page, you do not even need a controller at all to access this data, because you can leverage the $Setup global ...
user avatar
  • 143k
8 votes
Accepted

upsert on Custom Setting

By default if field is not specified then Salesforce uses ID field for upsert. If you want to explicitly specify other field, it should be defined as external Id. You may refer this post to ...
user avatar
  • 3,088
8 votes
Accepted

Test Method throwing null pointer exception on custom setting

You have to create your own test data. Isolation of Test Data from Organization Data in Unit Tests Starting with Apex code saved using Salesforce API version 24.0 and later, test methods don’t have ...
user avatar
  • 143k
8 votes
Accepted

Build an XML with a custom settings for migration in salesforce org to org

They are ordinary CustomObject entries, just as if you were migrating fields from Account or MyCustomObject__c. <?xml version="1.0" encoding="UTF-8"?> <Package xmlns="http://soap.sforce.com/...
user avatar
  • 438k
8 votes

Validate if a custom object or custom settings is used anywhere

What you're looking for is this feature (dependency API), but it's not available publicly yet. For now, the only sane way to do a check is to use a metadata deployment with a "check-only" option to ...
user avatar
  • 438k
7 votes

GetInstance vs GetValues (Custom Setting)

As the first comment on the question points out, getInstance() and getValues() do not always return the same object for hierarchical custom settings (although they do for list custom settings). The ...
user avatar
7 votes

Custom Setting in Validation Rule

The answer is NO - only hierarchical settings. However, there is VLOOKUP formula function that can reference a custom object where your state and country names can exist. See the zipcode example in ...
user avatar
  • 63k
7 votes

Custom MetaData Types reference in Formula Field

We are adding support for custom metadata type in formulas. In Spring '18 you will be able to reference CMT records in validation rules (pilot) with the future addition of formula fields, default ...
user avatar
7 votes

Custom MetaData Types reference in Formula Field

You can reference CMT records in formula fields starting with the Winter '19 release. It follows the same syntax as in validation rules: $CustomMetadata.MyCustomSetting__mdt.DeveloperName....
user avatar
7 votes

What is the use of "View All Custom Settings"?

This is basically adding an object-level security layer that didn't exist. Apex can always access Custom Settings, just as it can always query any object regardless of the user's object-level ...
user avatar
  • 10.7k
6 votes
Accepted

How can one access custom settings directly from javascript without using Apex?

Same as you would access them in visualforce: <script type="text/javascript"> var url = "{!$Setup.MyCustomSet__c.URL__c}"; alert(url); </script> If you google you won't miss it :...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible