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
NavneethNavneeth 

Retrieve List of all available apex class in organisation

Hi , 

 

 I have a requirement wherein i need to retrieve a list of all the apex classes that are available in my org in a custom visual force page. So wht shall i do to achive this. Wht will be controller of that particular  visualforce page. How can i get list of all apex classes in my organisation. 

 

Any sort of  help would be greatly appreciated. Thanks in advance.

 

Neha LundNeha Lund

Hi,

 

Page Code:

 

<apex:page controller="RetrieveClasses" action="{!names}">
  <apex:pageBlock >
  <!-- End Default Content REMOVE THIS -->
<apex:pageBlockTable value="{!classNames}" var="a">
<apex:column value="{!a.name}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:page>

 

 

Apex Code:

public class RetrieveClasses {

public List<ApexClass> classNames{set;get;}

public void names()
{
classNames=[SELECT id, name from ApexClass];
}

 

 

}

souvik9086souvik9086

VF PAGE

 

<apex:page controller="GetAllApexClasses">
<apex:form>
<apex:pageBlock>
<apex:pageBlockTable value="{!apexclassList}" var="apexclass">
<apex:column >
<apex:outputField value="{!apexclass.name}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Controller

 

public class GetAllApexClasses{
public List<ApexClass> apexclassList{get;set;}
public GetAllApexClasses(){
apexclassList = new List<ApexClass>();
apexclassList = [SELECT ID,Name from ApexClass];
}

}

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

swatKatswatKat

The Page :

 

<apex:page controller="AllApexClasses_Con">
 <apex:form >
    <apex:pageBlock >
        <apex:pageBlockTable value="{!AllClasses}" var="a">
            <apex:column value="{!a.Name}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
 </apex:form>
</apex:page>

 The simple controller : 

public class AllApexClasses_Con {

    public List<ApexClass> getAllClasses(){
        return [Select Name from ApexClass];
    }
}

 

prakher jain 10prakher jain 10
How to write test class for this controller.