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
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.
You should be able to use 'Tooling API' instead. Please have a look at this documentation
http://www.salesforce.com/us/developer/docs/api_toolingpre/api_tooling.pdf
-
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. Commented Sep 22, 2014 at 0:37