I'd like to give users the possibility to create sample Data after installing a package, but I want them to do this only if they want, so I don't provide the data creation directly in the postInstallScript. In fact I have a custom VF tab with a button that , if pressed, creates the sample data. The solution that I'm reaching for would be to have a situation where IF the package is installed for the first time (context.previousVersion() == null) the user has the possibility to create the sample data (creation handled by a class, this is not a problem), but if it's an upgrade, or if the user has already created the sample data, the action is avoided. So I need a static variable to store the information about wether or not data was created (IsSampleDataAlreadyCreated, something like this). How can this requirerment be accomplished? Is custom setting the solution?

1 Answer 1


Yes, I'd imagine you'd want a custom setting for this. Static variables only exist within a single transaction, so there would not be a way that a static variable would persist from one install to the next.

  • Yes , I know that static variable only "lives" within an execution context, I was wondering what kind of custom setting to choose, and related solutions. I'm thinking about a solution that provides a custom setting in the package, and a post install script that (if it is the first installation) create an instace of this custom setting (that has a checkbox field). So, the method that creates the data, can check the value of the checkbox and decide wether or not the data was already created.
    – user9959
    Commented Nov 3, 2014 at 16:48
  • But, for example, I ve some questions about the kind of custom setting. Protected or not? If protected, post install scripts cannot create instance in subscriber org, if public , instead, someone could delete the instance of that custom setting . Do you have other tips?
    – user9959
    Commented Nov 3, 2014 at 16:49
  • @ToninoTripodi As far as I'm aware, protected custom settings are available to install handlers, the same as any other code (except for a Known Issue regarding batchable classes). Do you have any documentation that suggests otherwise?
    – sfdcfox
    Commented Nov 3, 2014 at 16:54
  • help.salesforce.com/… CTRL+F "custom settings"
    – user9959
    Commented Nov 3, 2014 at 16:58
  • 1
    @ToninoTripodi Correct: "All data for the custom setting is hidden from the subscriber." Your package is not the "subscriber" and not subject to these limitations (otherwise, protected custom settings would be literally useless). Protected Custom Settings are designed to be an area your code can use to store data that literally cannot be accessed outside the package (without some sort of API to allow access), so you can guarantee that customers cannot tamper with your data. These settings can be accessed even during an InstallHandler script.
    – sfdcfox
    Commented Nov 3, 2014 at 17:04

You must log in to answer this question.