2


I am new for Salesforce/Apex programming. I am working on Community application. In my requirement I need to get some application level configuration data. I am using Custom Object to store my application level configuration. To get application level configuration data I am doing query and getting data from SalesForce with every request/flow.

I like to know that SalesForce community/Apex application support Application Context like concept so that I can store all of my application level data into it and use same to get application level data (I don’t like to query DB for every request/flow).

also like to know suggestion for following solution/flow
1. Create a singletone object to store Application level configuration data.
2. Upload Application data at the time of application installation.
3. Store all Application level data into Map.
4. Use SinleTone object to manipulate data (Update data in the table as well as in SinleTone Map).

Regards,
Sanjay

  • 1
    This question is very broad and contains multiple questions. I'd recommend reading the Force.com Fundamentals book (wiki.developerforce.com/page/Force_Platform_Fundamentals), first. It also sounds like you'll want to look into custom settings. – Mike Chale Feb 5 '14 at 15:28
  • 1
    I generally disagree with the flags in this case. The poster comes from a background of ASP-style server programming, and is trying to transfer this knowledge to the Force.com platform. They know what they want, but not quite how to ask. – sfdcfox Feb 5 '14 at 16:12
  • Sanjay, check out custom settings. I'm not 100% sure if they fit your use case here, but you might be able to refine this question a little after reading about them. I agree with @sfdcfox's points so leaving the question open. – Matt Lacey Feb 6 '14 at 0:34
3

Basically, you need "Custom Settings." They come in two flavors: "list" and "hierarchy". List configurations are ideal for storing lists of values, such as those that would apply to an entire organization, for example. The hierarchy type supports saving global, per profile, and per user configuration settings, such as which fields to display, email preferences, etc.

In both cases, custom settings are stored in the application cache. This cache can be accessed without queries, and can be "protected" against modification from outside your code. There is a limit to how much data can be cached, although this is generally not a problem for all but the largest of organizations.

You can initialize some default values on installation using an InstallHandler script. Typically, most developers build one or more Visualforce pages to allow a graphical configuration of the settings. Keep in mind though, that unlike ASP's "Application" object, which is a collection of static variables across one instance of a server, custom settings are accessible to all users in the organization at once, and are committed/saved in the same mannerism as normal database records.

In this sense, custom settings are more powerful than the Application object of a traditional server, because they are available to all users without any special syntax, even though salesforce.com is load-balanced across clusters of application servers.

Creating Settings

Setup > Develop > Custom Settings

Note that once you specify the type (list or hierarchy), it is locked in as that type. If there can only ever be one instance, consider a hierarchy (use only the org default value).

Uploading

Settings can be configured using the InstallHandler interface. This lets you set default values directly from code on installation.

Mapping

For lists, you access the values with CustomSetting__c.getInstance(string), where CustomSetting__c is the API name of the custom setting. There's no need for a map, per se, because it's immediately available from the cache. For hierarchy settings, CustomSetting__c.getOrgDefaults() will return the default values.

Singleton

CustomSetting__c.getOrgDefaults() is a singleton; only one instance of this value will exist in the cache at once. This is handled for you automatically, so there's no need to try and write a custom singleton. As an aside, all variables in salesforce.com are isolated by transaction, so there's no concept as a static variable that exists across all users currently using the system; custom settings are the closest approximation to this concept.

| improve this answer | |
  • Thanks sfdcfox . In first go it seems exactly what I am looking for. It contents all information which is sufficient to go further. – Sanjay Kharwar Feb 6 '14 at 7:53

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.