Assume there's a trigger on before-update of Account that sets Account.FIELD to "Value 1". A custom setting determines if it can run. This trigger along with related unit tests is included in a managed package.

Assume a client org has the same trigger that sets the same field to "Value 2".

If I attempt to install the package in the client org there may be an error due to failing unit tests (assume at the time of installation the packaged trigger runs before the local one, ignoring the fact that the order of execution is non-deterministic). Am I right?

What is the proper way to safely package the trigger?

Note that the 2 triggers can be easily controlled once the package has been installed. The problem is the package cannot control the client settings while it's being installed.

  • I'm not entirely sure unit tests run at all anymore on package installs. At least, they don't seem to. It'd be nice to confirm. – sfdcfox Jun 24 '16 at 23:52
  • @sfdcfox According to this document they run (see #12): developer.salesforce.com/docs/… – Mossi Jun 25 '16 at 2:15

When you install a managed package app none of the test classes execute .

Manage package Tests run only on below instances

1.On package upload (only applicable to the package author)

2.If explicitly selected to run (changing the namespace on the run dialog for Setup > Develop > Apex Test Execution, dev console, specific API calls to run them, like setting runTests in the metadata API deploy call).

3.On metadata API deployments that have the runAllTests flag set to true (see the runAllTests description).

  • Is this a recent change? I remember getting errors in the past during package upgrades. – Mossi Jun 25 '16 at 1:54
  • When you upload the package in your org where you have build the tests run but not when you install the package . – Mohith Shrivastava Jun 25 '16 at 1:55
  • @Mossi Did your package had post install scripts error might be there .I dont think you will run into errors if your app is manage package . – Mohith Shrivastava Jun 25 '16 at 2:00
  • @Mossi Things do change, and the manual is not the Source of All Truth. I know that I've installed apps that would have taken an hour or more if our tests run, and it was only a few minutes. – sfdcfox Jun 25 '16 at 2:18
  • @MohithShrivastava I am confused because I had heard otherwise from SF. Also see #12 here: developer.salesforce.com/docs/… – Mossi Jun 25 '16 at 2:18

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.