I need to store a few simple settings that describe the timing and behavior of an integration between Salesforce and a third party web app. In my former life, these things might have been stored in a config file or a few simple tables. The two main pieces of data are the sync frequency between the apps (hourly, daily, weekly, monthly) and a list of objects to be synced. I've searched around here and other places and came across some ideas for a singleton pattern with a custom object and also saw some references to environment variables global variables. Is there a best practice for storing this kind of static data in Salesforce? Thanks in advance for any suggestions!
There is a specialised form of custom object called a custom setting for this purpose.
These come in two flavors:
- Hierarchy Custom Settings: these are singletons by design
- List Custom Settings: these allow named instances
An advantage of using these instead of normal custom objects is that they are cached by the platform and if you use their normal API they do not count against governor limits. The hierarchy custom settings are also automatically made available in formula fields. And there is basic user interface provided by default to manage (set values for) the settings under Setup -> Develop -> Custom Settings. And you can write your own Apex/Visualforce to manage the settings.
The "hierarchical" part of the hierarchical custom settings refers to the ability to define an org-wide setting and then to also define profile or user specific overrides which can sometimes be useful.
Custom settings will do what you want, but there's a simpler alternative. Custom labels are easier to use if the limitations don't affect you. You are allowed 5000 custom labels per org. Each can be 1000 characters long. They are text values and are read-only. They can't be updated programmatically.
You access a custom label in Apex like this:
Program = Label.Current_Program; // Program is type String
In visualforce, the reference is as follows