Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


Public custom settings included as part of a managed package can be maintained by users of the target org if they have the Customize Application permission, which seems somewhat heavy handed, but it does work.

Protected custom settings are completely hidden, and can not be accessed via the GUI or via Apex; given that any records in the custom setting are not included in the package (i.e. it's empty in the target org). They could me modified and accessed via code in the managed package, so you could use them to store some dynamic values as determined by a user of your code/page.

The question:

If I wanted to use a list-type custom setting in a managed package in one of the most common use cases (i.e. storing a list of values I want cached, such as state codes) does this mean the only way to do so would be to check if there are any values there, insert a list if not, and then read them?

The insert would only happen the very first time and after that the caching would be efficient, but it seems like a bit of a work around for when you just want a static list—you might as well just use a static array inside a class.

share|improve this question
up vote 10 down vote accepted

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

share|improve this answer

I think there are three considerations here:

  1. Is the data static, or will it change as a result of user interaction
  2. How much data is involved
  3. Is the data identical for every subscriber

Custom settings are designed to be used where data is "written seldom and read often". If the data doesn't change then perhaps "written once read often" might be better provided in an Apex static Map as you say.

If you use a static map though you of course pay an overhead of script statements for initialisation and heap usage, so as the size of data increases, this approach becomes more expensive to your package-scoped governors.

If this cost is prohibitive, then as you suggest list custom settings will serve, and the answer already posted to use install scripts is a good one. However, the total size of custom settings is governed, and I think this is scoped to the org as a whole, and not to your package alone.

If the data may differ between subscribers then of course a static Apex Map will not do, and a protected list custom setting is the way to go. For a package publisher to be able to manipulate an individual subscriber's data in a protected custom setting using subscriber access in the publisher's LMO is a great strength of protected custom settings.

So, if the amount of data is relatively small, is static and identical across subscribers, I would opt for an Apex static Map.

share|improve this answer

You mentioned state lists, I suspect you have other settings going in there but as an FYI in Spring 13 SFDC finally is releasing - State and Country Picklists — Beta

Page 117

share|improve this answer
Yeah, I used that just for an example — I knew it was coming up but it's also one that everybody can relate to :) – LaceySnr Jan 11 '13 at 3:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.