function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
dptr1988dptr1988 

How do I store 'settings' for each user?

I'm wanting to create an apex page that will allow users to export contacts into another program, called BBP.

The problem is that each users has their own username and access key that the apex page needs to use to allow them to add a contact to BBP. I don't want the users to have to enter their username and access key each time they export a contact. So I'm wondering how I can store the username and accesskey for each user somewhere in the salesforce account.

I have read through the entire 'salesforce_apex_language_reference.pdf' and 'salesforce_pages_developers_guide.pdf' books but was not able to find anything that would allow me to store settings like that. The best I could find was in the 'ExampleController' code snippet that was demonstrating the difference between transient and non-transient variables. But non-transient variables appear to be erased when the sessions is closed ( ie user logged out or closed browser window ).




ArtabusArtabus
You could try to store it in a local browser cookie, or if needed in a custom field on the User object (with well defined field level securities)
dptr1988dptr1988
Storing a cookie would not be an option. I need something more permanent that will work on any computer that they use to login to. The data is closely tied to the user account. So that makes sense to store the data in a custom field in the User object.

The page needs to store more settings than just a username and access key. There are also some settings that determine the mapping of the SalesForce contact fields to the BBP contact fields. I would like some way that a 'System Administrator' could edit the default mappings and the page would use those default mappings unless the user had overridden them with some of his own. Where would I store the default mappings, as they are not associated with any user but with the page?
canonwcanonw
It sounds like BBP needs to know the user session id, and does some web service API query to salesforce.com.
dptr1988dptr1988
I am not wanting to have to create a 'plugin' or modification to BBP. BBP already has it's own remotely accessible XML API. All I am needing to do is POST a XML document to BBP from salesforce, that contains the API information. The XML document needs to contain the username and access key to validate the POST request. And I don't want the user to have to enter the username and access key each time.


Maybe a better way to ask this question would be Where/How do I store user data and program data for an apex page? For example, on linux the user data would be stored in the /home/joe_sample/.BBP/ and the global program data would be stored in /usr/share/BBP/ and on windows XP user data would be stored in the 'C:\Documents And Settings\Application Data\BPP\' and the program data would be stored in the registry or an .ini file at 'C:\Program Files\BBP\' Where/How would it be stored in salesforce?


werewolfwerewolf
Adding a custom field (one or more custom fields) to the User record would likely be your best approach, provided your users aren't skittish about having their credentials stored in those fields.
dptr1988dptr1988
It looks like that's my only option. I guess I'll have to forget about having 'default settings' that can be overridden be each user and just require each user enter his own settings.

I'm quite surprised that SalesForce doesn't have a convenient way for custom programs to store arbitrary data.

I'll see what I can do with custom fields in the User record.

Thank you all for you help!!



Message Edited by dptr1988 on 06-25-2008 04:45 PM
SteveBowerSteveBower
Could you create a custom object called something like "UserBBPSettings" which has a lookup reference to the User's Id.

Your code would look for a particular user's record in that object and take setting and credentials from there.  If not, it could use default settings from a "generic" user if the given user isn't found.), or present the user with a visualforce page to collect their authentication data to use and store.

The code would be Apex running with a level of security sufficient to CRUD the custom object, however standard users wouldn't have access to that object.

This is similar to just using extra fields in the User object, however the user won't see them.  However it would require you to write more visual force code to allow the user to administrate that custom object, reset passwords, etc.

Don't know if that helps, Steve.

dptr1988dptr1988
Yes, that helps a lot. Thank you!

That is a lot more like what I was wanting to do.

What do you mean by 'generic user' for getting the default settings from? I would like to make it so an 'administrator' could specify the default settings. So I guess I would just make the 'generic user' only modifiable by an 'administrator'? How would I create a 'generic user'? By putting a NULL value into the lookup reference to the User ID?




SteveBowerSteveBower

By Generic user I meant to implement something like having an extra field called "isDefault" on the custom object.  It would be false for all records except for the one record which you want to use for the default settings.  ( You have to make the reference to the user an optional field).

Then your code goes to look up the settings for a specific user and if it can't find a record for that user it queries for the record with "isDefault" set to true.

I suppose you could use a null reference ID as well as long as you make the reference an optional field.


Another option, if you have the user licenses to burn, is to just make one of the users the "generic" user.  Then you can just use custom fields on the User object, and hide them from the standard users with page layouts.

Best, Steve.
dptr1988dptr1988
Thank your very much for you help, Steve!! I think I finally have this figured out.