Is it possible to delete an apex class or apex trigger using Metadata API? Please guide. I tried using https://github.com/financialforcedev/apex-mdapi but it did not work.

3 Answers 3


That API might not allow it, but certainly you can delete files from the server using the metadata api, the deploy call, and a destructive changes file.

In terms of doing it from Apex, you can do it from the metadata api (though this would be the more complex way) or the partner api. Based on your other comments, it seems like you are talking about doing this in the context of a visualforce page, in which case I would recommend just using the ajax toolkit and the deleteIds call.


From the README on the project you linked to:

Note: The CRUD operations do not support Apex Class or Apex Trigger components sadly, this is a API restriction and not an issue with calling from Apex as such.

You cannot delete Apex Classes or Triggers from the Metadata API.

  • I read the README file. Is there any way we can delete Apex classes and Triggers using Apex?
    – Swati
    Jan 21, 2014 at 13:05
  • @AndrewFawcett : Is there any way we can delete Apex classes and Triggers using Apex? Please guide.
    – Swati
    Jan 21, 2014 at 13:08

You should be able to use 'Tooling API' instead. Please have a look at this documentation


  • can you provide more details / references in your answer on how to achieve this with the tooling api ? may be a sample code will be good. Sep 22, 2014 at 0:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .