67

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 Salesforce standard metadata types, such as custom fields, tabs, or workflow rules (obviously in this first release we don’t have the power required to duplicate ...


55

Just like normal SObjects, your Test Context doesn't have access to the custom setting records already in the database. Preferred solution You can perfectly, insert a new Custom Setting record, in your test context like you would normally do with an SObject Whatever_custom_setting__c setting = new Whatever_custom_setting__c(); setting.Name = 'Test Setting'...


37

For Hierarchy custom settings, you can get an instance, then populate and insert it: //fetches or creates a Custom Setting at the organization level HierarchySetting__c setting = HierarchySetting__c.getOrgDefaults(); setting.CustomField__c = 'http://salesforce.stackexchange.com/'; upsert setting; Or with List custom settings: new one up with the fields ...


28

What's your use case? One will fit better than the other. Hierarchy custom settings can be configured at varying user specificity levels under a single name; the platform will look for the most specific configuration first, then fall back / inherit to the least specific: setting per user, setting per profile, setting for whole org, Hierarchy custom ...


28

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.getOrgDefaults(); settings.SomeField__c = 'Some Value'; upsert settings custSettings__c.Id; Either way, basically you need to make sure SetupOwnerId is set to ...


22

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 themselves are considered to be Metadata. So, essentially, you have Metadata about Metadata. Technically, they are called “Components”, and the reason this is ...


16

If you use a "SELECT" statement, then they do count towards your query limit. However, since they are in the cache, you can access them through the various cache methods, such as getValues, getOrganizationDefault, etc.


16

You Can enable list custom setting schema Setting Page Setup > schema Setting Page > List custom Setting


14

You can use SOQL to query Custom Settings just like an object. Use a SQOL query to find the right value: select Tal_Source_Type__c, Tal_Source_Type__c from Tal_Sourc_Map__c where SF_Source_Type__c = :someval and SF_Source_Sub_Type__c = :otherval


14

Yes, they are. In fact changes you wouldn't think of as DML are also rolled back: calling @future method, sending email, and others. In essence outside of the current apex state rolling back undoes EVERYTHING you did. Note that Big Objects are the exception to this, they commit immediatley and do not support rollbacks. Even in tests. Platform events are ...


14

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 on governor limits. If you use a custom setting and access it using some of the methods provided, you are retrieving your data with zero impact on the ...


13

If I'm understanding correctly, I think this will work: Equipment_Chatter_Settings__c ecs = Equipment_Chatter_Settings__c.getInstance( UserInfo.getOrganizationId() ); if(ecs.Id == null) { ecs.Assignment_Chatter__c = TRUE; ecs.Loan_Return_Chatter__c = TRUE; ecs.Assignment_Body__c = 'Equipment ~1~ ~2~ was assigned on ~3~'; ...


13

I'd say it depends on how you are using the Map<String, CustomSetting__c> that getAll()returns and how may list records there are. If you are looping over the map values() searching for a single record based on a field other than the Name then SOQL would probably serve you better as you could just grab the required records. One thing to note with the ...


12

No, you must access them with a SOQL statement. However, SOQL queries against custom metadata do not increase the SOQL queries governor limit counter nor the SOQL query rows governor limit counter, so you can query them as frequently as you like.


11

According to this page, it is a known issue for which a patch is scheduled to be deployed tonight http://success.salesforce.com/issues_view?id=a1p30000000SU7PAAW


11

To note: I_ws is a single instance of WarrantyServices__c DSlst is a list<Driver__c> PSlst is a single instance of Part_Services__c Since they are all different types, you can't just create a list of all of them together. I suggest creating a subclass that includes all the types you'd like to return. Note: You can always create constructors and ...


11

Currently, triggers are not allowed on custom settings. If you're talking about custom settings in a managed package and wanting better validation, control, and the ability to add logic on the creation or update of a custom setting, you could always make the custom setting protected and then provide a Visualforce interface for creating and updating settings. ...


11

This is still valid, have a look at the System overview area of your org and you will see there is an indicator bar (shown in screenshot) that details the information you are talking about. I can verify this org has 14 custom objects and 2 custom settings (it is a throwaway dev org of mine I use for playing around in). 16/400 is also exactly 4%.


11

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 bound directly to an instance of the custom setting, then you get messed up by the custom setting security. I think this is similar to how VF enforces field ...


11

Custom settings are cached in a special application layer cache which allows a developer to access this data without performing a query, similar to how a CPU's cache allows it to access frequently accessed information without requesting the data from main system memory. All custom settings are cached, and each record in the cache counts towards the 10MB/1MB-...


11

Querying custom settings with SOQL will surely count against limits. The way custom settings should be used is via Apex methods for custom settings, not by using SOQL on them. Using SOQL defeats the purpose of using them. To access data from list-type custom settings use the following: List<Combinations__c> mcs = Combinations__c.getAll().values(); //...


11

here you go : MyCustomSetting__c cs = MyCustomSetting__c.getInstance('Days'); // you then have access to cs.active__c and cs.age__c


11

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? If no custom setting for the current user is defined then it returns a new custom setting and the ID will be blank. Otherwise the getInstance() should ...


10

I would recommend using the new Install Script functionality of managed packages. You could initialise the list when the package is installed (saves having to do the check in code you are proposing) Link to the InstallHandler interface documentation


10

Custom Settings are persisted in the database. However they're also cached. When using the cache methods Custom_setting__c.getAll(), .getInstance(), and .getValues(), Salesforce uses the cached values. If you use a SOQL query (SELECT id, name, etc FROM Custom_setting__c) to get data for a custom setting, Salesforce queries the database and uses one of your ...


10

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 use in Apex Code. You can now reference custom metadata types in validation rules. To do so, specify the object name, record name, and field value: $...


9

I think your only option is to create the Custom Setting records at the start of the test class. In that way your code can find them during the test. That also allows you to create test scenarios where the custom settings vary.


9

Add a custom list button to the custom object, and choose the "Show boxes for selection" box underneath the button type. When you add the button to the related list or list view, it will enable the checkboxes.


9

You can't change the visibility once set. If you need to change it, you must create a new custom setting. If you need to retain the data, you will need to copy the data. If this in a managed package, you can set an install handler script up migrate the data. If it is not a managed package, this setting has no effect, and there is no reason to change the ...


9

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 not consuming a query limit. However, both are still pretty fast so this sort of tuning probably isn't the best focus of optimization. This increase is must less ...


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