I want to delete a custom table using a code (not UI). Something like DELETE My_Object__c returns exception.

Can I do that ?

  • You need to pass an instance that has its Id value set so the system knows which record to delete. – Keith C Jul 19 at 14:00
  • @KeithC, i want to delete table, not record – Nazar Sokhan Jul 19 at 14:02
  • 1
    @NazarSokhan Sorry, my bad. Best you explain why in your question as such a delete is a lot easier done manually. – Keith C Jul 19 at 14:05
  • @KeithC, but is it possible to do this with code? – Nazar Sokhan Jul 19 at 14:13
  • Yes it is possible - see sfdcfox's answer - but dependencies can block the delete and it can only be done by a (dangerously high) privilege user. That is, there are enough gotchas that it is only a mechanism to use in narrow circumstances. – Keith C Jul 19 at 14:52

You can do this with the Metadata API. If you're using Apex, try using the Metadata Wrapper. You can't just ordinarily delete an object with a single line of code, it's more complicated than that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.