Take the 2-minute tour ×
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.

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!

share|improve this question

2 Answers 2

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.

share|improve this answer
    
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 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 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 –  crop1645 Jun 27 at 2:27
    
Great, thanks for your additional input. Very helpful! –  user886851 Jun 30 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}"/>
share|improve this answer
    
Thanks, I appreciate your response. This could be very handy. –  user886851 Jun 30 at 22:10
    
vote it up if you like it. There's no harm in voting for both answers. ;-) –  Jagular Jun 30 at 23:00

Your Answer

 
discard

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.