Skip links

Create VisualForce Page to Show Dependencies of any Classes/Objects in an Organization.

Working in Salesforce APEX is fun and gratifying due to its intuitiveness and elimination of setup and busy work by the Salesforce platform as compared to writing Java.

However, not everything is dummy-proofed and you can end up clobbering other code in Classes or Objects.  This VF (VisualForce) page and reference guide will help in future development in identifying dependencies on any object or class in apex classes.  You could also include ApexTrigger — swap object ApexClass in SOQL to ApexTrigger.

VF Page:

VF Page Code:

<apex:page controller="ApexClass_Search">
	<apex:form >
        <apex:pageBlock title="Search Apex classes">
            <apex:inputText value="{!SelectedObject}"/>
            <apex:commandButton value="Run"   rerender="Table"/>
        </apex:pageBlock>
        <apex:pageBlock title="list of Apex classes">
            <apex:pageBlockTable id="Table" value="{!AllClasses}" var="a" >
                <apex:column value="{!a.Name}"/>
                <apex:column value="{!a.Status}"/>
                <apex:column value="{!a.IsValid}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
     </apex:form>
</apex:page>

 Apex Controller Code:

public class ApexClass_Search {
	
	public String SelectedObject {get; set;}
 
	public ApexClass_Search (){	
     	SelectedObject='abaav';	
 	}
 
	public List<ApexClass> getAllClasses(){
    	List<ApexClass> allClasses =  [SELECT Id, NamespacePrefix, Name,  Status, IsValid, BodyCrc, Body FROM ApexClass where NamespacePrefix = '' ];
    	List<ApexClass> filteredClasses = new List<ApexClass>();
    	string selectObject = SelectedObject;
    	for(ApexClass ac: allClasses){
            if(ac.Body.containsIgnoreCase(selectObject) && selectObject != null){
            	filteredClasses.add(ac);
            	
        	}
    	}
    	return filteredClasses;
	}
}

Enjoy!  Let us know what you think.

Leave a comment