2

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.

2
  • 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
    Commented Jun 24, 2016 at 23:52
  • @sfdcfox According to this document they run (see #12): developer.salesforce.com/docs/…
    – Mossi
    Commented Jun 25, 2016 at 2:15

1 Answer 1

1

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).

10
  • Is this a recent change? I remember getting errors in the past during package upgrades.
    – Mossi
    Commented Jun 25, 2016 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 . Commented Jun 25, 2016 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 . Commented Jun 25, 2016 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
    Commented Jun 25, 2016 at 2:18
  • @MohithShrivastava I am confused because I had heard otherwise from SF. Also see #12 here: developer.salesforce.com/docs/…
    – Mossi
    Commented Jun 25, 2016 at 2:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .