6

Usually, when a trigger runs, we check what kind of a profile the user has, and if it's the kind where we don't want the triggers to run, then we exit the trigger before running any other code.

Problem: we have a SF package installed that we purchased from some other company, and all of its code is invisible to us, and is not editable. How can we stop some of those triggers from running other than manually disabling them through UI? I want to temporarily disable them while running a test class.

Was thinking about doing something like this, but got an error saying "DML not allowed on ApexTrigger."

ApexTrigger at = [select id from ApexTrigger where name='SomeTriggerName'];
at.status = 'Inactive';
update at;
Matt K
  • 7,207
  • 5
  • 39
  • 60
Kirill Yunussov
  • 1,955
  • 1
  • 21
  • 24
  • 2
    Do you have a good reason for wanting to disable it? I know test coverage is a pain, but it should be testing a real world scenario - if the trigger is going to run in the real world you want to make sure your code works with it! – Matt Lacey Jan 26 '12 at 21:11
  • The reason I need to disable it is because the test class checks many scenarios, and the packaged triggers run multiple SOQL statements, execution of which I cannot control. Before I can get the test coverage up to 100%, the SOQL query count hits the governor limit of 100 in the packaged namespace. – Kirill Yunussov Feb 21 '12 at 20:23

2 Answers2

4

I've tried doing something similar, and got stuck. I don't believe there's a way to do what you're asking without having the owner of the managed package update the Apex Code.

The approach you listed before the problem is a great solution; I would recommend using Custom Settings in addition, though. You could recommend to the owner/developer of the Trigger to implement a Custom Settings check before executing the Trigger(s). That's the best solution I could come up with for some of my own Triggers.

It would be great if the ApexTrigger object could be updated, but Salesforce doesn't allow it.

Matt K
  • 7,207
  • 5
  • 39
  • 60
1

I believe your only options are to uninstall or undeploy the managed package.

Jeremy Ross
  • 11,544
  • 3
  • 36
  • 36