what are the pros/cons of using force:package:install --apexcompile package? Will the package installations be prone to errors? will it have a negative effect to the destination orgs? Can't find much documentation about it.


By default, Apex Compilation is off for Sandbox, Scratch, and Developer Orgs, while it is turned on for Production Orgs. How Apex is executed has been described in several Dreamforce sessions, such as Peek Under the Hood of the New Apex Compiler. It's a rather long watch, but I dare say it'd be insightful.

That said, here goes:

force:package:install --apexcompile package


Minimizes installation time, as only the package's code will be compiled.


Loading times for dependent code will be longer the first time it is used after installation. For example, if A uses B, and B is upgraded as part of a package, then A will not recompile until the next time it is used.

Dependent code units may fail if a dependency is broken (e.g. a method is renamed or removed as a result of installing the package), which may necessitate further revisions to code. Again, given A uses B, if B removes a critical code path for A, then A will fail to compile at the next run, and will need to be fixed, or the package with B be fixed.

force:package:install --apexcompile all


Dependencies will already be resolved, guaranteeing that dependent code units will work. The documentation isn't perfectly clear on this, but I would imagine that a failed compilation step would result in the package failing to install.

First time load characteristics will also be drastically improved, desirable for orgs where the code won't change often and is mission-critical (i.e. Production Orgs).


Longer installation times will be required.

So, why would we use --apexcompile package at all? Simply put, we use this mode to minimize deployment times to orgs meant for development and testing, including Sandboxes and Scratch Orgs. This can save a considerable amount of time (many minutes or even hours), which can be especially important in a Continuous Integration (CI) setup. One package's install could easily hold up others, creating a backlog for QA and UAT.

For deployment to production or production-like orgs (some training orgs, for example), you'll probably want to go with --apexcompile all to make sure that training and business processes are not held up by lengthy post-install lethargy (imagine a VF page taking 1 minute to load instead of 2 seconds). For orgs where code changes infrequently, this should be the ideal mode to use.

I'm pretty sure I heard somewhere that --apexcompile all would be forced on Production Orgs, to prevent post-install issues, but I can't seem to find any confirmation of such. If you're absolutely not sure which mode to use, leave it as "all" until/unless you can verify it won't break anything. --apexcompile package should be considered "dangerous" and should be handled with care.

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.