Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I stop a managed trigger from executing while running a test class?

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;
like image 549
Kirill Yunussov Avatar asked Jan 26 '12 18:01

Kirill Yunussov


People also ask

How do you stop trigger execution in Test class?

If you want to default the trigger to off, have your handler set bypassTrigger = Test. isRunningTest() . That way, you can still toggle it on/off when you run certain tests in your suite.

How do you stop trigger execution?

DEACTIVATE THE TRIGGERDeactivate your trigger in your sandbox by unchecking the Active checkbox of the trigger. Create an outbound change set, upload and deploy the change set to production. Tadah! The trigger in production will be deactivated.

Can we disable managed package trigger?

We can't deactivate managed package triggers. Check hierarchical custom setting in a managed package if there is a way to enable/disable any functionality.

How do I disable trigger in Apex test class?

1. Probably the simplest way to delete / disable is to connect to your Salesforce production org from VS Code download the apex class / trigger, change the status of the Apex class / trigger to “Deleted” or “Inactive” in the class/trigger XML file and save.


Video Answer


1 Answers

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.

like image 152
Matt K Avatar answered Oct 22 '22 15:10

Matt K