+ Start a Discussion
Med Usa1Med Usa1 

How can I delete trigger from production ?

Hello,

 

I try to delete a trigger and its test class from production.

I follow this process :

 

Using the IDE:
1) Assuming you have a sandbox environment synchronized with your Prod org, you will first want to inactivate the trigger in sandbox.  You can refresh your IDE project to consume these changes
2) In the Sandbox org, you will then want to run all tests: Navigate to Setup->Develop->Apex Classes and click "Run All Tests".  This will run all of the tests in the sandbox org.  This is an important step to validate whether or not the inactive trigger has impacted any asserts within your test methods.  Assuming this behavioral change has impacted your tests, you will need to update your asserts to reflect this.
3) Once all tests are passing, you can now deploy these changes to your production environment.  You can use the Deploy to Server wizard in the IDE.  Simply select the tests that you have modified, as well as the inactive trigger, and deploy these changes to your production environment.
4) Validate the trigger is now inactive in your production environment.

Deleting the trigger (if necessary - an inactive trigger will not fire and therefore can be considered as "soft deleted")
5) Create a new IDE project against your Active production org.
6) Right click on the specified trigger and select delete.  Accept the option to delete from server.  Since the trigger is inactive - it can now be deleted from the production environment.

But I can't deploy an inactive trigger, I have this error :

Failure Message: "System.AssertException: Assertion Failed: Expected: 1002, Actual: null", Failure Stack Trace: "Class.PI_Num_Auto_Increment_Test_Class.validate_PI_Num_Auto_Increment: line 38, column 9 External entry point"

 

Can you explain me how can I do this deletion ?

 

Thank you.

eric.luiseric.luis

On the Force.com IDE (or Eclipse with plugin), you can open the metadata file (xml) and change the status to "Deleted", then save.

sornasorna

You are getting this error because the assert in that test method is assuming that the trigger is still active. So, you should modify the assert method. 

You may not get this error in sandbox because test results may differ between sandbox and prod due to fact that sandbox don't have much data as production. 

Med Usa1Med Usa1

Eric, So I have just to change the status to Deleted in the metadata file for the trigger and the test class ? There are 2 metadata files, one for each ?

 

Sorna, I follow the instructions and they say to change status to inactive for the trigger.

How can I change my test class to cover this code ? I don't understand because if the status is inactive, the test class can't run...

 

Thank you.

sornasorna

If the test class is written specifically to cover this trigger, then you can delete the test class too. 

eric.luiseric.luis

Yes, change for deleted and save the xml. I think it is better to change to inactive first.

No, each class has 1 metadata file and the code file.

Med Usa1Med Usa1

Hello,

 

In Eclipse, for a trigger or a test class, there are 2 files : XXXX.trigger and XXXX.trigger-meta.xml.

I need to delete all ?

 

Thank you.

eric.luiseric.luis

No, you need to open the XXXX.trigger-meta.xml and change the status to inactive and then deleted.