1

I want to deactivate a trigger on an object or all the triggers on an object using apex code using metadata api or partner api, but i'm not finding a way to do it exactly. Could anyone plz help with that.

4

You could do this from Force.com IDE.

Find the trigger.meta.xml of respective trigger and make this change and deploy.

<?xml version="1.0" encoding="UTF-8"?>
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>40.0</apiVersion>
    <status>Inactive</status>
</ApexTrigger>
| improve this answer | |
3

If the triggers are in your own code base, you can add your own switch (or switches):

public class Triggers {
    public static Boolean areDisabled = false;
}

trigger AccountTrigger on Account (after insert, after update) {
    if (Triggers.areDisabled) return;
    ....
}

Or the Metadata API for ApexTrigger includes the status value that can be set to Active/Inactive/Deleted. You can call that from Apex.

| improve this answer | |

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.