2

We have created a managed package which consist of multiple custom setting objects with multiple handler classes.Now in Post Install Script field,We are able to add only one handler class.How can we insert our remaining handler classes?Any suggestions?

1 Answer 1

6

Solution: one InstallHandler class to rule them all

We create separate install handler classes, each of them taking care of a single responsibility (ie: create custom settings, upgrade to a new data format, create some default records). They all implement the InstallHandler interface, but they are public as opposed to global.

Then we have one main installhandler, the one we configure as the package post install script, which calls them all. Something like this:

global class MainInstallHandler implements InstallHandler {

    global void onInstall (InstallContext context)
    {
        new CreateSettingsInstallHandler().onInstall(context);
        new CreateDefaultRecordsInstallHandler().onInstall(context);
        new MigrateOldDataInstallHandler().onInstall(context);
    }
}

Each of the classes above is a public class that implements InstallHandler. Like this:

public class CreateSettingsInstallHandler implements InstallHandler
{
    public void OnInstall (InstallContext context)
    {
         // Do Stuff
    }
}

This has two main advantages: you can create unit tests for each class separately, and there is only one global class, so your other installer classes are not locked in the package.

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.