How to Create a Custom App Settings Page?

I would like to create a custom app package that provides the user with a setup interface in which they can input their own preferences, which inputs will then be referenced by apex code. I will be using VisualForce to create the page, of course.

For example, I would like the user to be able to specify a user in a lookup field, and whoever they specify will be assigned certain records (this logic is part of the apex class, just need to plug in the user ID). They will also specify picklist values that represent standard object fields so that these fields are plugged into logical statements in the apex code. My goal is to have much of the code be taylored to the end user by user input via this setup page.

Here is the key question I keep circling back to: what is the best way to store the user inputs in the system so they can be referenced by the code? I only know of two ways to do this: custom object and custom settings, but neither is a perfect solution. Custom settings are too limited given the available field types (i.e. no picklists, no lookups). With a custom object I would need to make it so the first time the setup page is configured, it inserts a custom object record (or can I insert the record initially as part of the package installation…?), that is then updated by subsequent updates to the setup page. This feels messy and I don’t want my users to be able to access the record directly (though if this is the only way I would like to know any best practices I should be aware of). Also, I would prefer not to have to rely on a specific record that needs to be queried to store this key setup information, but would rather have a more global and static method of doing so.

Are there any suggestions or best practices for this type of custom setup page that someone can please help guide me with?



We had similar requirement and we opted custom settings over custom object.There are known advantages of using custom setting over custom object. From Salesforce documentation:
Custom settings data is exposed in the application cache, which enables efficient access without the cost of repeated queries to the database.This data can then be used by formula fields, validation rules, flows, Apex, and the SOAP API.

The drawback of less number of available datatype can be handled by your setup visualforce page.For example you can show a pick list to user on user-interface and store value in text field. Similarly bind some other lookup field on user interface and before save assign value to custom setting object field.

At the time we developed this solution Custom Metadata Types were not available.At present, I feel Custom Metadata Types are more close to your requirement as they are deployable and are flexible to be used in managed packages.

I hope that helps.

Source : Link , Question Author : Brig Larimer , Answer Author : Mukesh Verma

Leave a Comment