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

How to select and delete apex class in VF page

Hi all,
        I write the code for view the list of apex class name in VF page and select and delete the apex class name. But i got the error
Compile Error: DML not allowed on ApexClass at line 12 column 6.  how to fix to solve this error and how to delete the the apex class name in VF page Please help  below is my code...

public class RetrieveClasses{
  public void del(){
    List <ApexClass> li=new List <ApexClass>();
     for(sObjectWrapper wrap:wrappers)    
     delete li;
    // update li;
  public void triggerdel(){
   List <ApexTrigger> trggerlist=new List <ApexTrigger>();
   for(sObjectWrapper sobj:wrapp)
   //delete trggerlist;

  public List<sObjectWrapper> wrappers{get;set;}
  public List<sObjectWrapper> wrapp{get;set;}

public RetrieveClasses()
private List<sObjectWrapper> getdata(){
wrappers = new List<sObjectWrapper>();
for(ApexClass app:[select id,name,apiversion from ApexClass where apiversion=36.0])
   wrappers.add(new sObjectWrapper(app,false));
return wrappers;

private List<sObjectWrapper> gettrigger(){
List<sObjectWrapper> wrapper = new List<sObjectWrapper>();
for(ApexTrigger aptg:[select id,name from ApexTrigger])
wrapper.add(new sObjectWrapper(aptg,false));
system.debug('trigger values'+wrapper);

return wrapper; 
//public boolean isSelected{get;set;}

    public class sObjectWrapper{
    public boolean isSelected{get;set;}   
    public ApexClass apx{get;set;}
    public ApexTrigger apt{get;set;}

    public sObjectWrapper(ApexClass apx,Boolean isSelected){
     this.isSelected = isSelected;
     this.apx = apx;
    public sObjectWrapper(ApexTrigger apt,Boolean isSelected){
     this.isSelected = isSelected;
     this.apt= apt;

You cannot delete apexclass like this. Please go through this doc ( that says

 Although Apex classes and triggers have the Create and Update field properties, a runtime exception occurs if you try to create or update them using the API.

However, nothing is mentiond about delete() call but I believe same is true for Delete() call too. You need to use IDE or the Ant Migration tool. Although, there are other who have used metdata API in APEX. You may check this (

Hi Abhishek, 
             Thanks for your response,  i refere above the link, can i able to delete the apex class without IDE  and eclips?
i will delete the apex class on production please give any idea..