function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MarkL.ax269MarkL.ax269 

Force.com IDE deactivating triggers in production

Maybe I'm missing the obvious here, but I can't figure out how to deactivate a trigger in a production environment. I created a simple trigger in the sandbox, tested and deployed it to production. Everything works fine and the trigger works as expected in production. However now I would like to deactivate and/or undeploy it from production. In the sandbox I can edit the trigger and uncheck the IsActive field, but I can't edit the trigger in production (I am the system administrator) because there is no Edit link.

I tried deactivating in the sandbox and then redeploying to production, but that didn't work either. Do I need to write a deployment script, access the metadata, use Ant? Without the ability to roll back triggers from production, I can't use Apex. What am I missing? I searched all the documentation and this forum and didn't find anything other than references to the UI checkbox, which doesn't exist in production.

Mark

Message Edited by MarkL on 02-21-2008 09:48 AM
Best Answer chosen by Admin (Salesforce Developers) 
MarkL.ax269MarkL.ax269
My current best guess is there is an active tag in the XML file for the trigger, and deploying with that tag set might deactivate it. But I don't have the syntax and the xml doesn't already contain a tag for it. This is the entire xml file.

Code:
<—xml version="1.0" encoding="UTF-8"–>
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>11.1</apiVersion>
</ApexTrigger>

 

All Answers

MarkL.ax269MarkL.ax269
My current best guess is there is an active tag in the XML file for the trigger, and deploying with that tag set might deactivate it. But I don't have the syntax and the xml doesn't already contain a tag for it. This is the entire xml file.

Code:
<—xml version="1.0" encoding="UTF-8"–>
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>11.1</apiVersion>
</ApexTrigger>

 

This was selected as the best answer
MyGodItsColdMyGodItsCold
I experienced the same thing. I developed in a Spring 08 sandbox and deployed to Winter 08 Production.

What I was told is that when Spring 08 goes in, we will be able to edit the IsActive checkbox.

Fortunately for us, we can wait until Friday night. So, we're just sitting here with a trigger in force - but no data load. Not really bad.

What we learned is to reserve one of our Sandboxes as the "play-pen" for next upgrade preview. In that manner, we'll have the sandbox with all our data mirrored on the same release level as Production.

jpizzalajpizzala
I am actually trying to figure out how to enable an Apex trigger in production, since it has deployed as inactive. We are currently on the Spring '08 release and the edit functionality has not been enabled ( through the UI ).

When I spoke with SF tech support this morning, they told me that there is an "is active" flag that you set in the trigger itself, but I have not found any documentation regarding this.

Does anyone know where to look?
MarkL.ax269MarkL.ax269
Thanks, that's good information. Fortunately it's a simple hello world trigger and has no impact, but we are looking at deploying real triggers soon. I can wait until Friday night too, hopefully that takes care of it!

Mark
MyGodItsColdMyGodItsCold
I didn't get the <active>false</active> entry to work in the xml.
jpizzalajpizzala
Yeah, I figured it would be a configuration setting as well, but the support tech insisted that it was in the Apex trigger itself...I don't know what the rationale behind this implementation method could be.
MarkL.ax269MarkL.ax269
Still nothing? I'm upgraded to Spring 08 now and there's still no way to disable it in the UI and while the XML file has the tag now, setting it to false does nothing - it's still active. I tried the same change in my sandbox, setting the active tag to false, and it worked as expected.

So how do you disable a trigger in production?

Mark
Ron HessRon Hess
i believe you must deploy a trigger which is marked inactive, or one which contains an empty body.
DucatiracerxDucatiracerx
I currently use Eclipse to dev and deploy, with the Force.com platform it will generate the .xml config file for you in Eclipse.

Here is my code for the XML,

<?xml version="1.0" encoding="UTF-8"?>
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
    <active>true</active>
    <apiVersion>11.1</apiVersion>
</ApexTrigger>

This is autogenerated by Eclipse as part of the web service for the trigger.

I am having the same problem though, the trigger tests and deploys but when I set to active it will not change on prod?

Any ideas?
MyGodItsColdMyGodItsCold

Since we really want the trigger we finally got into production, I didn't try this - but if you delete the trigger from your project (obviously, you'd save a copy somewhere), and then choose the Deploy to Server option from when you highlight the project, right click and choose Force.com - the system will recognize it's on the server, but no longer in the Eclipse world. So, instead of the Green Add or Yellow Overwrite, you should see the Red Delete highlighting when you want to check which items you're going to work with on this particular deployment.

Good luck, let us know.

MarkL.ax269MarkL.ax269

Ron Hess wrote:
i believe you must deploy a trigger which is marked inactive, or one which contains an empty body.




I just tried this. I updated the active tag in the sandbox to false and saved it to the server - I should mention I'm using an Apex sandbox. This worked perfectly, the trigger was deactivated in the sandbox. Then I tried to deploy the trigger to production and got several issues.

  1. The deployment plan shows a huge number of adds and overwrites.  This should not be possible since I refreshed the sandbox on 2/7 and have not made any material changes to production since then.  However we were upgraded to Spring 08 on 2/15...please tell me I don't need to refresh it again, I've got a lot of test data and recreating it would be a huge undertaking.
  2. The updated trigger is listed as "No Action" - the only change I made was to the active tag, I didn't update the code itself.  But shouldn't this still show as an Overwrite?
  3. I tried to check it and validate anyway, and got an error:  "ZipException: ZIP file must have at least one entry"

So I just added a comment to the trigger to force a change.  This caused it to show in the deployment plan as an Overwrite.  Ok so far.  Then I tried to validate the plan and got a test coverage error of 0%.  I can only assume this is because I'm deactivating the trigger since coverage was 100% when it was active.

Finally I tried to deploy it anyway, ignoring the test coverage error.  This of course resulted in an error and my trigger is still active in production.  Some comments:

  1. There should be a way to deploy selected components.  Bringing up a deployment plan that shows everything and automatically checks all the adds and overwrites (which are incorrect, see above) seems very risky.  Good thing I'm the only one testing this.
  2. Updating the xml should "count" as an update.
  3. On the deployment plan step 3 window, the button should be "Deploy" instead of Next - otherwise it doesn't look like you're about to commit a change.  Also seems risky.
  4. I also get a synchronize issue problem, but I started another thread about that.

I hope this is constructive, I really like what you have done so far.  This has been the real missing link in development on the platform and it's a HUGE step forward.  Keep up the good work!

Mark

ps - I also updated the subject of this thread since it seems to focus on the IDE

Message Edited by MarkL on 02-21-2008 09:49 AM
MarkL.ax269MarkL.ax269
Any comments?  Salesforce has been pretty silent on this issue.
MyGodItsColdMyGodItsCold

Yesterday, I addressed the issue in our tcon w/ our agent. He suggested we comment out the code.

I then asked how to get 75% code coverage. He wasn't sure.

 

This will work (99% guaranteed ... I think).

Choose 2 fields you're not using (if you're using all the Fields, on all the objects, you have my profound sympathy ... you might even want to change the trigger to work on a little used (or custom) object. Test to see if field1 has changed. If so, add an object to the list of objects to update, and set field2 to some value (e.g. "changed"). Then, write your testMethod to create an object, change the field1 and assert that field2 will be what you set it to.

 

 

"Not everything worth doing is worth doing right." - Tracy Kidder, Soul of a New Machine.

 

hokusaihokusai

I got

 

<?xml version="1.0" encoding="UTF-8"?>

<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">

<active>false</active>

<apiVersion>12.0</apiVersion>

</ApexTrigger>

to work on a trigger that is unpackaged, but on my trigger within a package it did not work.  Eclipse just saves locally and not to the server.  Any ideas?  Has anybody ever set <active> to false in a trigger in a package?
jpizzalajpizzala
Have you tried deploying with the Ant tool? I've noticed that the IDE doesn't always tell you when there is an error during deployment. The Ant tool may give you a better idea as to what is going wrong.
hokusaihokusai
thanks I will try that next time, but I think it is too late.  I already deployed the trigger.  Now I want to set active to false,  and I can't. 
jpizzalajpizzala
You can still change the <active> tag in the meta to false and deploy with Ant if you aren't having any luck with the IDE. Not guaranteeing 100% success, but it may shed light on the problem at hand.
jeremyfrey1jeremyfrey1
 
Basically, I want the ability to create and edit triggers and apex code in production, with the stipulation that the active checkbox would not be enabled, and the trigger would be disabled if the code did not meet the minimum code coverage requirements.  The side effect, of course, would be that we would be able to deactivate / activate well-tested triggers on the fly.
mat_tone_84mat_tone_84

try this:

 

<?xml version="1.0" encoding="UTF-8"?>
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>14.0</apiVersion>
    <status>InActive</status>
</ApexTrigger>

mjackmetavantemjackmetavante

I'm having a problem going the other way.  I create the trigger in the IDE, no problems.  I create a class to test it, %100 code coverage. 

 

I can deploy to production, no problems, but making a change to the status in the xml does nothing, and there's no way to change the value in production.

MyGodItsColdMyGodItsCold

Did you try the remedies proposed in previous posts? [Delete from project, then deploy; commenting out all code - or deleting it all & then doing some 'no op' code; etc.]

 

Have you asked SF? One of the good things (or bad things - depending upon point of view), is that there are such frequent (usually totally painless) updates.

mjackmetavantemjackmetavante

I triend deleting it from project, then deploying with all code commented, I tried making some trivial code changes

but what I always wind up getting is changes to the xml are only saved locally, and do not deploy to production. 

 

On the last run through, my test class vanished into the ether, so now I'm mucking with that again to get my test coverage.  

MyGodItsColdMyGodItsCold

2 things.

 

First, there's got to be a way to delete or make it go Inactive. Become the squeaky wheel until SF shows you how to make it happen (or does it for you).

 

Second, on "my test class vanished" - do you have in instance where SF either lost or rendered unusable your .cls? or did you do it locally & did a save to server - without backup on something like Subversion (not that I know anyone whose ever done that, or done it myself;)

mjackmetavantemjackmetavante
When I say vanished into the ether, I mean overwritten by the default blank one, on the server and in the IDE.  I'm sure it was something I did incorrectly, as I'm pretty new to this process, but it was nonetheless quite aggravating. 
stangstang
A Solution...

After struggling with deactivating a trigger, I finally figured it out with the help of Premier support. However, it is a can of worms because upon deployment of the change from Active to Inactive, your test case will still run and your code coverage will probably fail because the trigger is not fired. The ridiculous solution is to modify the test case to invoke the class called by the trigger, and then when re-activating the trigger, take that line out of the test case. This probably only happens if your trigger invokes external classes (as mine did), but in my opinion this still makes absolutely no sense. However, that is what I was told I needed to do.

The better solution is to, in the metadata XML file for your trigger, set the Status to "Delete" instead of "Inactive". Run deployment and the trigger will be removed. When you are ready to re-activate the trigger, deploy it again with the status set to "Active". In the long run this will save a lot of time. No mucking with your test cases. It is very easy.

In either case -- whether you choose to set Status to Delete or Inactive, ther is one pesky issue here that I ran into and others might be encountering...I noticed that if you set the status in the metadata file using the pick-list and then, in Eclipse, click the "Force.com->Save to Server" menu selection for that metadata file, it changes it back to what it was before you changed it! In other words, if Status was previously set to "Active" and you changed it to "Inactive" and then clicked "Force.com->Save to Server", that action changes it back to "Active". So just make the change using the Status drop-down and do not save the change. It will be saved automatically.
JAW99JAW99

Delete is not valid status Eclipse tells me.

Seriously, I just want to shut this **bleep** trigger off for a while. Delete, inactivate, this thread is 3 pages of people stugglring with this. Why isn't this simpler?

BManojKumarBManojKumar

Hi All,

 

I do not know why you people are making this very complex. If you want to deactivate a trigger in production , change the status of the trigger in sandbox as mentioned below and deploy it to production.

 

Cool..

 

<?xml version="1.0" encoding="UTF-8"?>
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>16.0</apiVersion>
    <status>Inactive</status>
</ApexTrigger>

to again activate the trigger , just change the status to Active and deploy it to production.

If you still have any queries fell free to drop a mail to me at manoj.kumar@emdiesels.com

Cheers..

Enjoy Working..

Manoj

NenzNenz

The way that I have found that works best for me to 'deactivate' a trigger is to simply create a custom setting Boolean var.. something like disableXXXTrigger [true/false] and then create a util method that looks at this setting and just wrap the trigger logic with it.. ie...

 

That way your not relient on meta data or others things that SFDC may change and you can change this in the UI without any dev tools.

(Utils contains code to retrieve the custom setting)

 

 

trigger XxxTrigger on Contact (before update) {
    Utils u = new Utils();
    if(!u.isDisableXxxxyTrigger(UserInfo.getProfileId())) {
      ///Do trigger stuff
    }
}

 

 

Kirill_YunussovKirill_Yunussov

That's what we have started doing as well - via boolean vars in Custom Settings.   This way you can enable/disable triggers in Production immediately, without having to redeploy anything.

schow 12.ax1442schow 12.ax1442

I need to do this as well.  Can you please include example of what you defined in the custom settings?  Based on your code, is Utils the name of the custom setting?  The if statement taking the current user logon, what is that comparing against?  Did you create a column in the custom setting to also stamp the user you want to allow to bypass this trigger?

sfdcFanBoysfdcFanBoy


There are a number of ways to stop a trigger to run.  I've consolidated the list.  Read here
https://sfdcfanboy.com/2017/11/23/a-tip-a-day-23-5-ways-to-stop-trigger-in-production/  (https://sfdcfanboy.com/2017/11/23/a-tip-a-day-23-5-ways-to-stop-trigger-in-production/)