3

Implementing an InstallHandler allows a managed package to execute setup Apex code on install or upgrade of the package.

I'd like to have some unrelated code - a trigger - behave differently for this install/upgrade case. A static Apex flag - set at the start of the InstallHandler implementation - is the first thing that comes to mind. But before I add that, is there any other mechanism already there to detect this context?

4
  • 1
    It will all run in the ghost user context. IIRC there are some tell tail markers that it is the ghost user, not a real user.
    – Phil W
    Oct 16 at 15:48
  • Hi @PhilW, But are any cleaner than the simple static?
    – Keith C
    Oct 16 at 16:22
  • 1
    Hmmm. I guess not.
    – Phil W
    Oct 16 at 16:47
  • 1
    I concur. There's no specific method that outright tells you about InstallHandler or SandboxPostCopy status (e.g. like System.isBatchable). You'll need to set a static variable instead.
    – sfdcfox
    Oct 16 at 17:34
4

Just for the record, consensus is an Apex static variable that the InstallHandler implementation sets and other code tests i.e.:

/**
 * Referenced by triggers.
 */
public inherited sharing class Triggers {
    
    /**
     * Want to special case logic related to install handlers: the InstallHandler
     * implementation can set this and other code e.g. trigger logic can check it
     */
    public static Boolean isInstallHandlerContext = false;

    ...
}

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.