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
kathyanikathyani 

How do I delete triggers from salesforce

Hi,

I had EmployeeBefore and EmployeeAfter triggers. I deleted them from Eclipse but how do I get rid of it in SF. I created a new trigger called EmployeeTrigger. When I run tests it is still executing those two deleted triggers along with Employee Trigger. So for some reason I need to delete it from Salesforce. Under src, I right clicked on Triggers and said save to server but it is still executing both before and after triggers.


Quick help would be appreciated.

thanks in advance,
kathyani
Best Answer chosen by Admin (Salesforce Developers) 
tmatthiesentmatthiesen
The following steps will allow developers to delete active triggers from Production orgs.

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.

You can use a similar approach with the Ant Migration toolkit.  Simply update the test classes and trigger, as detailed above, and deploy.  You can then use the destructivechanges.xml to remove the trigger.

All Answers

gregsgregs
if the triggers are in a production account you will need to undeploy them using ant ant script or eclipse.  if they were in another org such as a developer org or sandbox, you should be able to remove them from the server through eclipse, however, first update them with the active flag set to false (in the metadata file associated with the trigger) and then delete it since you cannot delete an active trigger but must make it inactive first
kathyanikathyani
Ok, thanks. I was able to delete it from SF. Clicked on setup -> create -> objects. Then clicked on the object and under triggers section I was able to delete the triggers which I did not need.
VisualForceVisualForce

Hi,,

    Can u explain how to delete trigger from sf Production org. In my production my trigger in inactive stage. eventhough i couldnt find delete button in my production org.. how is it possible....

kathyanikathyani
I am sorry I do not know about SF production but I was trying to delete my trigger from staging environment. I am guessing it should be the same, I might be wrong.

I have developers edition. So went to Sales force web UI. Logged in. Then clicked on setup on top of the page. Then clicked on create which is displayed on the left column of the page. Clicked on objects under create. You will see a list of sobjects that you had created for your application. Click on an object for example Employee object. Then scroll down and you will see a section triggers where you will find list of triggers created for that object. Select the trigger which you do not need and delete.

Let me know if this worked.

VisualForceVisualForce
Thanks for ur reply...
 
        In  sandbox and developer edition we can delete a trigger.. But I have to delete a trigger in my production org..
 
Thanks once again...
tmatthiesentmatthiesen
The following steps will allow developers to delete active triggers from Production orgs.

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.

You can use a similar approach with the Ant Migration toolkit.  Simply update the test classes and trigger, as detailed above, and deploy.  You can then use the destructivechanges.xml to remove the trigger.
This was selected as the best answer
GoForceGoGoForceGo

 

Step 5 and 6 fails - when I delete the trigger in Eclipse, it is not deleted from the server. Interestingly, a window pops up momentarily which seems to want to give me the option to delete it from server, but the window vanishes before I can  click on it.I am using Eclipse 3.3.1.1 and IDE 19 or 20.

 

I had to resort to following steps I found on another thread.

 

  • Delete the Trigger in the Sandbox via the web interface (Object -> Triggers -> Del)
  • Within Eclipse I did a "Refresh from server" on the Sandbox -- this made the files disappear
  • Within Eclipse I then deployed to Production, ticking the "Delete" line in the deployment list

 

 

WaveWave

Actually, what you just suggested used to work fine for me, but not a while ago I could no longer see any 'delete' rows on step 3 of the deployment, even after the triggers were inactivated and deleted from my sandbox.

This is when I've tried 5 and 6 (deleting the trigger directly from the production (on Eclipse) after they have been inactivated and deployed) and it worked!

Med Usa1Med Usa1

Hello,

 

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

I follow your process but I can't deploy an inactive trigger, I have an error.

Can you explain me how I can do this deletion ?

 

Thank you.

 

Shannon Andreas 21Shannon Andreas 21
I see this is an old post, however, in my dealings with code, I have found that the only measure I could take here was to "deactivate" the trigger in sandbox, then change set to Production.

Anyone have a reason why this would not be sufficient and a "safe" practice?