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
pedrosampaiopedrosampaio 

Package - How to define configuration variables

Hi.

 

I am developing a new package and I need to define some configuration variables.

 

Note,that the configuration variables can be updated by users during the app lifecycle.

 

What migth be the best way to implement this?

 

I have tried to use Custom Settings but when I deploy the package in a new org, the variables values get lost.

 

What am I doing wrong? Or is there a better way to implement this?

 

Is there a way to run code when the package is deployed?

 

 

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

You are going about it in the generally correct way; you do generally want to use Custom Settings for this type of configuration. However, as you have observed, the settings can't be copied into a new org when installed. Furthermore, you can't run "on-install" code. So, basically, you need to do something about this limitation. The two most common design patterns are (a) forcing the user to visit a configuration page if the settings are missing, or (b) providing a set of defaults if no settings are found.

 

Method A results in users being forced to go to a settings screen, which may be inconvenient at that particular moment. Method B results in an easier time for the users, but they may never configure the app (or even know it can be configured). It's really a matter of personal preference. I would probably choose method B, personally. You can maybe include a little warning message on a VF page if they're using default settings, and invite them to update the settings on a settings page.

All Answers

sfdcfoxsfdcfox

You are going about it in the generally correct way; you do generally want to use Custom Settings for this type of configuration. However, as you have observed, the settings can't be copied into a new org when installed. Furthermore, you can't run "on-install" code. So, basically, you need to do something about this limitation. The two most common design patterns are (a) forcing the user to visit a configuration page if the settings are missing, or (b) providing a set of defaults if no settings are found.

 

Method A results in users being forced to go to a settings screen, which may be inconvenient at that particular moment. Method B results in an easier time for the users, but they may never configure the app (or even know it can be configured). It's really a matter of personal preference. I would probably choose method B, personally. You can maybe include a little warning message on a VF page if they're using default settings, and invite them to update the settings on a settings page.

This was selected as the best answer
Salesforce Partner 4Salesforce Partner 4
Hello, is that Answer still relevant in 2022, are these the only options? I am trying to design an App and I need to know the best practices for configuring the app during installation to provide key data relevant to how the app works, I need to provide configuration variables that would affect the metadata created during installation. They would also affect the decision to create and add some buttons in specific object layouts, etc...