Skip to main content

Show all project component (apex class, Visualforce page, customobjects etc )in Single Visualforce page

 Here is sample code to view all project related components in Visualforce page (apex class, vf pages, permission set, public groups etc)


Class Code :-
public class Project_Components {

    transient public List<displayListWrapper> displayList{get;set;}
    transient public List<ApexClass> ClassList{get;set;}
    transient public List<PageClassWrapper> pageClassList{get;set;}
    transient public List<PermissionSet> permissionSetList{get;set;}
    transient public List<Group> publicGroupList{get;set;}
    transient public List<ProcessDefinition> processList {get;set;}
    transient public List<ApexTrigger> triggerList {get;set;}
    transient public List<ApexComponent> apexComponentList{get;set;}
    transient public Map<String,String> objectNameVsLabelMap{get;set;}
    transient public List<ObjectRelationshipWrapper> objectRelationList{get;set;}
    public boolean isCollapsibleSection{get;set;}
    public String collaspeAllButtonText{get;set;}
    public Integer debugNum{get;set;}
    public Integer size{get;set;}
    public String debugstr{get;set;}
    public List<String> objectList;
       
    public Project_Components (){
        collaspeAllButtonText='Group All';
        toggleCollpsibleSection();   
        objectPermissionSetMappings();
        getClassList();
        PageVsClass();
        objectRelationship();
        apexComponents();
        triggers();
        processes();
    }    
    
    public class newClass{
        public String ObjectName{get;set;}
        public String PermissionSets{get;set;}        
        public newClass(String n, String i){
            this.ObjectName=n;
            this.PermissionSets=i;
        }
    }
    
    public void toggleCollpsibleSection(){
        if(isCollapsibleSection==true){
            isCollapsibleSection=false;
            collaspeAllButtonText='Group All';
        }
        if(isCollapsibleSection==false){
            isCollapsibleSection=true;
            collaspeAllButtonText='Collapse All';
        }
    }
   
    public class PermissionSetWrapper{
        public String psName{get;set;}
        public String psLabel{get;set;}
        public PermissionSetWrapper(String name, String label, List<ObjectPermissions> oP){
            this.psName=name;
            this.psLabel=label;
        }                                     
    }
    
    public class displayListWrapper implements Comparable{
        public String ObjectLabel{get;set;}
        public String ObjectAPIName{get;set;}
        public String ObjectSetupURL{get;set;}
        public String ObjectPermissionSets{get;set;}
        
        public displayListWrapper(String oname, String oapiname, String osetupurl){
            this.ObjectLabel=oname;
            this.ObjectAPIName=oapiname;
            this.ObjectSetupURL=osetupurl;
            this.ObjectPermissionSets=null;
        }
       
        public Integer compareTo(Object o){
            Integer returnValue=0;
            displayListWrapper obToCompareWith=(displayListWrapper)o;
            if(this.ObjectLabel.equals(obToCompareWith.ObjectLabel))
                returnValue=0;
            if(this.ObjectLabel>obToCompareWith.ObjectLabel)
                returnValue=1;
            if(this.ObjectLabel<obToCompareWith.ObjectLabel)
                returnValue=-1;
            return returnValue;
        }
      }
    
    public class PageClassWrapper{
        public Id PageId{get;set;}
        public String PageName{get;set;}
        public String stdCtrlName{get;set;}
        public String ctrlName{get;set;}
        public String extName{get;set;}                
        
        public PageClassWrapper(Id i, String a, String b, String c, String d){
            PageId=i;
            PageName=a;
            stdCtrlName=b;
            ctrlName=c;
            extName=d;
        }
    }
    
    public class ObjectRelationshipWrapper{
        public String objectName{get;set;}
        public List<FieldDetailWrapper> objectRelationList{get;set;}  
        
        public ObjectRelationshipWrapper(String obName, List<FieldDetailWrapper> fList){
            objectName=obName;
            objectRelationList=fList;
        }
    }
    
    public class FieldDetailWrapper{
        public String relatedObjectName{get;set;}
        public String relatedFieldName{get;set;}
        public String lookupOrMD{get;set;}
        public String primaryOrSecondaryMD{get;set;}
        public String relationshipName{get;set;}
        public FieldDetailWrapper(){
            relatedObjectName=null;
            relatedFieldName=null;
            lookupOrMD=null;
            primaryOrSecondaryMD=null;
            relationshipName=null;
        }
        public FieldDetailWrapper(String robName, String rFldName, String rLUOrMD, String rpOS, String rName){
            relatedObjectName=robName;
            relatedFieldName=rFldName;
            lookupOrMD=rLUOrMD;
            primaryOrSecondaryMD=rpOS;
            relationshipName=rName;
        }
    }
    
    public void objectPermissionSetMappings(){
        
        Map<String, String> permissionSetDetails;
        List<String> oNameList;
        Map<String, Schema.SObjectType> allObjects = Schema.getGlobalDescribe();
        objectList=new List<String>();
        displayList=new List<displayListWrapper>(); 
           
        List<PermissionSet> pSet=[SELECT Id, Label FROM PermissionSet WHERE Label like '%  your project namespace %' ORDER BY Name ASC];   
        Map<Id,String> pMap=new Map<Id,String>();
        for(PermissionSet ps: pSet)
            pMap.put(ps.Id,ps.Label);

        permissionSetList=pSet;
        
        //Iterate through the list of objects and filter  Objects and add the API name to objectList 
        for(String sIterator : allObjects.keySet()){
        
            if(sIterator.startsWithIgnoreCase('your project namespace')&&sIterator.containsIgnoreCase('__c')) 
                objectList.add(sIterator);
                
        }
        //Describe the objects in 'objectList', save API name in 'oNameList' to be used as Argument in SOQL to find the URL
        Schema.DescribeSObjectResult[] oProp=Schema.describeSObjects(objectList);
        oNameList=new List<String>();
        for(Schema.DescribeSObjectResult it: oProp){
                oNameList.add(it.getName().replace('__c',''));
        }
        
        //Get Setup Edit URL for Object
        List<EntityDefinition> objectSetupURLList=[SELECT DeveloperName,DurableId FROM EntityDefinition WHERE DeveloperName IN :oNameList];
        Map<String,String> objectSetupURLMap=new Map<String,String>();
        for(EntityDefinition x: objectSetupURLList){
            objectSetupURLMap.put(x.DeveloperName,x.DurableId);    
        }
        
        //add the data in displayList
        for(Schema.DescribeSObjectResult it: oProp){
            displayList.add(new displayListWrapper(it.getLabel(),it.getName(),objectSetupURLMap.get(it.getName().replace('__c',''))));
        }
        displayList.sort(); 
        
        //Pick the API Names of objects
        List<String> obAPIList=new List<String>();
        for(displayListWrapper  dIterator: displayList)
            obAPIList.add(dIterator.ObjectAPIName);
            
        //Run query to bring ParentId from ObjectPermissions
        List<ObjectPermissions> obPerms=[SELECT ParentId,SobjectType FROM ObjectPermissions WHERE SobjectType IN :obAPIList ORDER BY SobjectType ASC];
        Map<String,List<Id>> permMap=new Map<String,List<Id>>();
        permissionSetDetails=new Map<String,String>();
        
        //Add data to a map where Key is objectAPI name and Value is List of permission sets
        for(String oname: obAPIList){
            List<Id> temp=new List<Id>();
            String j='';
            for(ObjectPermissions osd: obPerms){
                j='';
                if(osd.SobjectType.equals(oname)){
                    temp.add(osd.ParentId);                
                }
                Integer i=0;
                for(Id b: temp){
                        if(i==0||i==(temp.size())){
                            if(pMap.get(b)!=null)
                                j=pMap.get(b);
                        }
                        else{
                            if(pMap.get(b)!=null)
                                j=pMap.get(b)+', '+j;
                        }
                    i++;
                }
            }
            permissionSetDetails.put(oname,j);
        }
        
        for(displayListWrapper dIterator: displayList)
            dIterator.ObjectPermissionSets=permissionSetDetails.get(dIterator.ObjectAPIName);
    }
    
    public void getClassList(){
        ClassList=[SELECT Name FROM ApexClass WHERE Name like '% your project namespace %'];
    }
    
    
    public void viewObjectFields(){
        String objectProp=ApexPages.currentPage().getParameters().get('objectProp');
        SObjectType objectType = Schema.getGlobalDescribe().get(objectProp);
        Map<String,Schema.SObjectField> mfields = objectType.getDescribe().fields.getMap();
    }  
    
    public void apexComponents(){
        apexComponentList=[SELECT Id,Name FROM ApexComponent WHERE Name LIKE 'your project namespace %' ORDER BY Name ASC];
    }
    
    public void publicGroups(){
        publicGroupList=[SELECT Id, Name FROM Group WHERE Name LIKE 'your project namespace %' ORDER BY Name ASC];
    }
    
    public void workflows(){
       // workflowlist=[SELECT Id,Name FROM workflow WHERE Name LIKE 'your project namespace%' ORDER BY Name ASC];
    }
    public void processes(){
        processList=[SELECT Id,Name FROM ProcessDefinition WHERE Name LIKE 'your project namespace %' ORDER BY Name ASC];
    }
    public void triggers(){
        triggerList=[SELECT Id,Name FROM ApexTrigger WHERE Name LIKE 'your project namespace %' ORDER BY Name ASC];
    } 
    
     public void PageVsClass(){
        String stdCtrlName='';
        String ctrlName='';        
        String extName='';
        pageClassList=new List<PageClassWrapper>();
        List<ApexPage> PageList=[SELECT Name, Markup FROM ApexPage WHERE Name like 'your project namespace%' ORDER BY Name ASC];
        
        for(ApexPage aPage: PageList){
            Integer intvariable, startPoint, endPoint;
            String stringVariable=aPage.Markup;
            if(stringVariable.contains('standardController')){
                intvariable=stringVariable.indexOf('standardController=\"')+('standardController=\"'.length());
                startPoint=stringVariable.indexOf('standardController=\"')+('standardController=\"'.length());
                endPoint=stringVariable.indexOf('"',intvariable);    
                stdCtrlName=stringVariable.substring(startPoint,endPoint);  
            }
            else
                stdCtrlName='--';
                
            if(stringVariable.contains('extensions')){
                intVariable=stringVariable.indexOf('extensions=\"')+('extensions=\"'.length());
                startPoint=stringVariable.indexOf('extensions=\"')+('extensions=\"'.length());
                endPoint=stringVariable.indexOf('"',intvariable);    
                extName=stringVariable.substring(startPoint,endPoint);
                if(extName.contains(',')){
                    String inputStr=extName;
                    extName='';
                    String[] extArray=inputStr.split(',');
                    for(Integer k=0;k<extArray.size();k++){
                        if(k!=extArray.size()-1)
                            extName+=extArray[k].trim()+', ';
                        else
                            extName+=extArray[k].trim();
                    }
                }
            }
            else
                extName='--';
                
            if(stringVariable.contains('controller')){
                intvariable=stringVariable.indexOf('controller=\"')+('controller=\"'.length());
                startPoint=stringVariable.indexOf('controller=\"')+('controller=\"'.length());
                endPoint=stringVariable.indexOf('"',intvariable);    
                ctrlName=stringVariable.substring(startPoint,endPoint);
            }
            else
                ctrlName='--';
           
          pageClassList.add(new PageClassWrapper(aPage.Id,aPage.Name,stdCtrlName,ctrlName,extName));              
        }
    }
    
    public void objectRelationship(){
        objectNameVsLabelMap=new Map<String,String>();
        Map<String, Schema.SObjectType> allObjectMap= Schema.getGlobalDescribe();
        List<String> ObjectList=new List<String>();
        //added  by VT
        Schema.DescribeSObjectResult[] descResult = Schema.describeSObjects(objectList);
        
        for(Schema.DescribeSObjectResult i1: descResult){
            String obName=(String)i1.getName();
            if(obName.contains(' your project namespace ')&&(!obName.contains('History')&&!obName.contains('Share'))){
                ObjectList.add(i1.getName());
                objectNameVsLabelMap.put(i1.getName(),i1.getLabel());
            }
        }
        
        List<Schema.DescribeSObjectResult> ObjectDescribeResult=Schema.describeSObjects(ObjectList);
        List<FieldDetailWrapper> fieldList;
        objectRelationList=new List<ObjectRelationshipWrapper>();
        for(Schema.DescribeSObjectResult i2: ObjectDescribeResult)
        {
            fieldList=new List<FieldDetailWrapper>();
            Map<String, Schema.SObjectField> ObjectFieldsMap=i2.fields.getMap();
            for(Schema.SObjectField s5: ObjectFieldsMap.values()){
                Schema.DescribeFieldResult ob3=s5.getDescribe();
                if(ob3.getRelationshipName()!=null&&ob3.getSobjectField().getDescribe().getName()!=null){
                    FieldDetailWrapper fdwObj=new FieldDetailWrapper();
                    fdwObj.relatedObjectName=objectNameVsLabelMap.get(ob3.getSobjectField().getDescribe().getName());
                    fdwObj.relatedFieldName=ob3.getLabel();
                    fdwObj.lookupOrMD=ob3.getRelationshipOrder()==null?'Look-up':'Master-Detail';
                    if(ob3.getRelationshipOrder()!=null){
                        if(ob3.getRelationshipOrder()==1)
                            fdwObj.primaryOrSecondaryMD='Primary';
                        else
                            fdwObj.primaryOrSecondaryMD='Secondary';                            
                    }
                    fdwObj.relationshipName=ob3.getRelationshipName();
                    fieldList.add(fdwObj); 
                }
            }
            ObjectRelationshipWrapper orwObj=new ObjectRelationshipWrapper(i2.getLabel(),fieldList);
            if(orwObj.objectRelationList.size()>0)
                objectRelationList.add(orwObj);
        }
    }
     
}



Visualforce Page:-

<apex:page controller="Project_Components" showHeader="false" lightningStylesheets="true" tabStyle="account">
    <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" lang="en">
        <apex:slds />
        <div class="slds-scope">
            <div class="slds-container--center slds-box slds-container--x-large slds-theme_shade slds-theme_alert-texture container-fluid">
                <div class="slds-page-header">
                  <div class="slds-page-header__row">
                    <div class="slds-page-header__col-title">
                      <div class="slds-media">
                        <div class="slds-media__figure">
                          <span class="slds-icon_container slds-icon_container_circle slds-icon-action-description" title="Description of icon when needed">
                          <svg class="slds-icon" aria-hidden="true">
                            <use xlink:href="/apexpages/slds/latest/assets/icons/action-sprite/svg/symbols.svg#description"></use>
                          </svg>
                          <span class="slds-assistive-text">Description of icon when needed</span>
                        </span>
                        </div>
                        <div class="slds-media__body">
                          <div class="slds-page-header__name">
                            <div class="slds-page-header__name-title">
                              <h1>
                                <span style="margin: 8px;" class="slds-page-header__title slds-truncate" title="">Component</span>
                              </h1>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div> <br/>
                <apex:form title="Component">
                    <apex:actionFunction name="viewObjectFields" action="{!viewObjectFields}" reRender="fieldTable">
                        <apex:param id="param1" name="objectProp" value=""/>
                    </apex:actionFunction>
                        <apex:pageBlock tabStyle="Account"  title="Permission Set - ({!permissionSetList.size})" mode="view" >
                            <apex:pageBlockSection collapsible="true" columns="3" showHeader="false" title="Details" >
                                <apex:repeat value="{!permissionSetList}" var="pIterator">
                                    <apex:pageBlockSectionItem >
                                         <apex:outputLink target="_blank" value="/{!pIterator.Id}">{!pIterator.Label}</apex:outputLink>
                                    </apex:pageBlockSectionItem>
                                </apex:repeat>
                            </apex:pageBlockSection>
                        </apex:pageBlock>
                        <apex:pageBlock title="Object Label, API Names and Permission Sets" tabStyle="opportunity">
                            <apex:variable value="{!1}" var="counter"/>
                            <apex:pageBlockTable value="{!displayList}" var="objectVar" id="objectTable"  >  
                                <apex:column headerValue="S No." >
                            {!counter}
                            <apex:variable value="{!counter+1}" var="counter"/>
                            </apex:column>
                                <apex:column headerValue="Object Label">
                                    <apex:outputLink target="_blank" value="/{!objectVar.ObjectSetupURL}">{!objectVar.ObjectLabel}</apex:outputLink>
                                </apex:column>
                                <apex:column value="{!objectVar.ObjectAPIName}" headerValue="Object API Name"/>
                                <apex:column value="{!objectVar.ObjectPermissionSets}" headerValue="Permission Sets"/>
                            </apex:pageBlockTable>
                        </apex:pageBlock>
                    <apex:pageBlock title="Pages - ({!pageClassList.size})" tabStyle="Case">
                        <apex:variable value="{!1}" var="counter"/>
                        <apex:pageBlockTable value="{!pageClassList}" var="pageIterator" styleClass="pageTable">
                            <apex:column headerValue="S No." >
                        {!counter}
                        <apex:variable value="{!counter+1}" var="counter"/>
                        </apex:column>
                            <apex:column headerValue="Page Name">
                                <apex:outputLink target="_blank" value="/{!pageIterator.PageId}">{!pageIterator.PageName}</apex:outputLink>
                            </apex:column>
                            <apex:column value="{!pageIterator.stdCtrlName}" headerValue="Standard Controller Name"/>
                            <apex:column value="{!pageIterator.ctrlName}" headerValue="Controller Name"/>
                            <apex:column value="{!pageIterator.extName}" headerValue="Extensions"/>                                
                        </apex:pageBlockTable>
                    </apex:pageblock>
                    
                    <apex:pageBlock title="Apex Classes - ({!ClassList.size})" tabStyle="Lead">
                        <apex:pageBlockSection columns="3">                
                            <apex:repeat value="{!ClassList}" var="classIterator" >
                                <apex:pageBlockSectionItem >                        
                                    <apex:outputLink target="_blank" value="/{!classIterator.Id}">{!classIterator.Name}</apex:outputLink>
                                </apex:pageBlockSectionItem>
                            </apex:repeat>
                        </apex:pageBlockSection>
                    </apex:pageBlock>
                    <apex:pageBlock title="Apex Components - ({!apexComponentList.size})" tabStyle="Account">
                        <apex:pageBlockSection collapsible="false"  rendered="true" columns="3" >
                            <apex:repeat value="{!apexComponentList}" var="aCompIterator">
                                <apex:pageBlockSectionItem >
                                    <apex:outputLink target="_blank" value="/{!aCompIterator.Id}">{!aCompIterator.Name}</apex:outputLink>
                                </apex:pageBlockSectionItem>
                            </apex:repeat>
                        </apex:pageBlockSection>
                    </apex:pageBlock>
                    <apex:pageBlock title="Triggers - ({!triggerList.size})" tabStyle="Contact">
                        <apex:pageBlockSection collapsible="false"  rendered="true" columns="3" >
                            <apex:repeat value="{!triggerList}" var="trigIterator">
                                <apex:pageBlockSectionItem >
                                    <apex:outputLink target="_blank" value="/{!trigIterator.Id}">{!trigIterator.Name}</apex:outputLink>
                                </apex:pageBlockSectionItem>
                            </apex:repeat>
                        </apex:pageBlockSection>
                    </apex:pageBlock>
                    
                    <apex:pageblock title="Object Relation - ({!objectRelationList.size})" tabstyle="Opportunity">
                        <apex:pageBlockSection collapsible="false"  rendered="true" columns="1">
                            <apex:pageBlockTable value="{!objectRelationList}" var="orlIterator" styleClass="pageTable">
                                <apex:column headerValue="Object Name" value="{!orlIterator.objectName}"/>
                                <apex:column headerValue="Related Object Information">
                                    <apex:pageBlockTable value="{!orlIterator.objectRelationList}" var="orlIter">
                                        <apex:column value="{!orlIter.relatedObjectName}" headerValue="Related Object Name"/>
                                        <apex:column value="{!orlIter.relatedFieldName}" headerValue="Related Field Name"/>
                                        <apex:column value="{!orlIter.lookupOrMD}" headerValue="Relation Type"/>
                                        <apex:column value="{!orlIter.primaryOrSecondaryMD}" headerValue="Relation Category"/>
                                        <apex:column value="{!orlIter.relationshipName}" headerValue="Relation Name"/>
                                        <br/>
                                    </apex:pageBlockTable>
                                </apex:column>
                            </apex:pageBlockTable>
                        </apex:pageBlockSection>
                    </apex:pageblock>
                </apex:form>
            </div>
        </div>
    </html>

</apex:page>

Popular Posts

Apex Test Class Examples for @HttpPost Exposed WebService Class

Introduction: In Salesforce, the Apex programming language allows you to create powerful web services that can be exposed to external systems for data integration. One common scenario is using the @HttpPost annotation to create a custom RESTful web service. In this blog post, we'll walk through some examples of how to write effective test classes for an @HttpPost exposed web service class in Salesforce. Writing comprehensive test classes ensures that your code is robust, functional, and ready for deployment.

Uninstall all Windows 10 default apps using Powershell

Here is script to uninstall all windows 10 default modern apps. This script uninstalls xbox, xbox Game bar, Xbox App,Xbox Gaming Overlay, Get started etc from your computer. No need to run one by one commands Just copy below script, run  powershell as administrator and paste script and press enter . It will automatically uninstall all default programs.  If you do not  want to uninstall some apps than just remove " "  line from script. $packages = @( "7EE7776C.LinkedInforWindows" "C27EB4BA.DropboxOEM" "Microsoft.3DBuilder" "Microsoft.Microsoft3DViewer"

Must-listen songs for developers

Here are some must-listen songs for developers: "Strobe" by deadmau5 . This electronic dance music (EDM) track is perfect for getting into a flow state. The repetitive beat and simple melody are easy to focus on, and the overall mood of the song is upbeat and motivating.  "Viva la Vida" by Coldplay . This rock song has a soaring melody and powerful lyrics that can inspire you to stay focused and productive. The song's message of hope and resilience is perfect for those times when you're feeling stuck or discouraged.  "Code Monkey" by Jonathan Coulton . This tongue-in-cheek song is a hilarious and accurate portrayal of the life of a software developer. The lyrics are catchy and the song's upbeat tempo will make you want to get up and dance.  "The Sound of Silence" by Simon & Garfunkel . This classic folk song is perfect for those times when you need to focus and concentrate. The song's slow tempo and haunting melody will h...

How to Save Quote PDF, Send PDF, Preview PDF in salesforce with custom functionality

Want to develop custom pdf viewer, save pdf in quote pdf related List and Send quote to customer on button click when quote is custom in salesforce . These functionality are standard from salesforce. but you can develop these functionality custom in salesforce. Here is the solution:- Custom button to save Quote PDF and send PDF  Step 1:-  First Create Two custom button. which will used for PDF preview and Save quote pdf in quotes pdf related list.                               1. PDF preview Button                              2. Save & Send Quote Button Replace "Your VF page here" to Your quote PDF cuatom page. Step 2:-  PDF preview button   pdf preview button will display the pdf's preview in standard format of salesforce. So you need to set the  following configuration (In picture). After that you have ...

Unveiling the Power of Named Credentials in Salesforce with Comprehensive Code Examples

Introduction: Named Credentials are a powerful feature in Salesforce that allow you to securely authenticate and connect to external services and APIs without exposing sensitive information like usernames and passwords. In this blog post, we'll delve into the world of Named Credentials, understand their significance, and provide you with in-depth code examples to illustrate their implementation in various scenarios.

Unleashing the Power of Flow Orchestrator in Salesforce: Streamlining Business Processes

Introduction: Salesforce Flow Orchestrator is a powerful tool that enables businesses to automate and streamline complex business processes within the Salesforce platform. With its intuitive visual interface, advanced workflow capabilities, and seamless integration with other Salesforce features, Flow Orchestrator revolutionizes how organizations manage and optimize their processes. In this blog post, we will explore the features, benefits, and potential of Flow Orchestrator in driving operational efficiency and productivity. 1. Simplifying Complex Business Processes: Flow Orchestrator empowers business users to design and execute complex workflows without the need for extensive coding or technical expertise. Its visual interface allows users to create dynamic flows, define decision points, and automate repetitive tasks, all while maintaining a clear and intuitive process design. 2. Enhanced Automation with Conditional Logic: Flow Orchestrator offers advanced conditional logic c...

Salesforce LWC Code for Multi-Select Lookup

Introduction: In Salesforce Lightning Web Components (LWC), implementing a multi-select lookup field can enhance the user experience and provide greater flexibility for selecting multiple related records. In this blog post, we will walk through the process of creating a multi-select lookup field using LWC. We will cover the required code snippets and provide step-by-step instructions to help you implement this functionality in your Salesforce org.