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.

  • Thanks, this looks interesting. In reading over the custom settings from your link, it looks like once a setting has been saved, it can't be changed. That seems a bit limiting as I do need the admin to be able to change the choices made for sync frequency and/or objects sync'd. Did I read that right?
    – user886851
    Jun 26 '14 at 20:04
  • 2
    @user886851 The values can be changed by a System Administrator through the default UI (that's usually how we use them). And if you need less privileged users to change them you can write a bit of Apex/Visualforce and choose which profile users have access rights to that. So I think you picked it up a bit wrong.
    – Keith C
    Jun 26 '14 at 20:12
  • 1
    If I had to do it over again, I'd leverage org-wide hierarchical custom settings, for the simple reason that they are accessible in formula fields AND validation rules whereas list custom settings are not available in these use cases. Sadly, you can't write VR on custom settings themselves so if you need to validate values for legitimacy as opposed to trusting the sysad to always be 'right' - you'll need a VF page/controller
    – cropredy
    Jun 27 '14 at 2:27
  • Great, thanks for your additional input. Very helpful!
    – user886851
    Jun 30 '14 at 22:08

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

<apex:outputLabel value="{!$Label.Current_Program}"/>
  • Thanks, I appreciate your response. This could be very handy.
    – user886851
    Jun 30 '14 at 22:10
  • vote it up if you like it. There's no harm in voting for both answers. ;-)
    – Jagular
    Jun 30 '14 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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