About

all about SFDC

Sunday 17 April 2016

Search Apex Classes in Your Sandbox

Hello Everybody,  Do you ever had a thought created a page to Search and Display Apexclasses. Please have a look at this snippet and it will works in Every Sandbox and Developer Editions and You can also Create for Pages Search as well except for the Managed packages which comes inbuild isolated body and of the class
Hope you like It! Have fun of Coding!


Search View


View Body



Apex Class:
public without Sharing class ApexControllerSearch {
    Public string inputtext{get;set;}
    Public List ApxLst{get;set;}
    Public boolean flagshow{get;set;}
    public string clsName{get;set;}
    public ApexClass Apxcls{get;set;}
    public boolean pb1{get;set;}
    public boolean pb2{get;set;}
    
    Public ApexControllerSearch(){
    flagshow = false;
    pb1=true;
    ApxLst = new List();
    Apxcls = new ApexClass();
    
    }    
    
    Public void actionSupMethod(){
    
     system.debug('inputtext-->'+inputtext);
     ApxLst.clear();
     Apxcls.clear();
     //string clas = '(hidden)';
    flagshow = true;
    if(inputtext!='')
    {
      
      flagshow = true;
      ApxLst = database.Query('select name,Status from ApexClass where name like '+'\''+'%'+inputtext+'%'+'\''+' limit 20');
    }
    if(String.IsEmpty(inputtext)|| ApxLst.size()==0)
    {
    flagshow = false;
    }

    }

    public void ApxCl()
    {
    getCls();
    
    
    }
    
    public ApexClass getCls()
    {
    pb1=false;
    pb2=true;
    flagshow = false;
    //ids='0039000001WeRlR';
    Apxcls = new ApexClass();
    Apxcls = [select Name,body from ApexClass where name=: clsName limit 1 ];
    system.debug('----------------> ' +Apxcls );
    return Apxcls;
    
    
    }
    Public void Reset()
    {
    inputtext='';
    actionSupMethod();
    }


}
VF Page:


<apex:page controller="ApexControllerSearch" >
  <apex:form id="fm" >
      <apex:pageBlock >
        Type Apex Class Name Here :<apex:inputText value="{!inputtext}" html-placeHolder="Search..." id="Text" >
          <apex:actionSupport action="{!actionSupMethod}" event="onkeyup" reRender="outptText,pb,fm2" />
        </apex:inputtext>
        <apex:commandButton value="Search" action="{!actionSupMethod}" reRender="outptText,pb,fm2" />
        <apex:commandButton value="Reset" action="{!Reset}" reRender="outptText,pb,fm2,fm" />
      </apex:pageBlock>
      </apex:form>
 
<apex:form id="fm2">
    <apex:pageblock rendered="{!flagshow}" id="pb" >
 
      <apex:pageblocktable value="{!ApxLst}" var="Cl" id="outptText" >
      <apex:column >
        <apex:commandlink Value="View" action="{!ApxCl}" status="pageStatus" rerender="fm2" style="color:blue;" >  
        <apex:param value="{!Cl.name}" name="Sel" assignTo="{!clsName}" />
        </apex:commandlink>
        </apex:column>
        <apex:column value="{!Cl.name}"/>
        <apex:column value="{!Cl.Status}"/>
      </apex:pageblocktable>
    </apex:pageblock>
 
<apex:pageblock title="Apex Class" rendered="{!Apxcls.body!=null}" >
<apex:inputTextarea id="newDesc" value="{!Apxcls.body}"/>
<apex:pageBlockButtons >
<apex:commandButton value="Back" action="{!actionSupMethod}" reRender="outptText,pb,fm2"/>
 
</apex:pageBlockButtons>
    </apex:PageBlock>
 
 
 
  </apex:form>
</apex:page>
Powered by Blogger.

Contact form

Name

Email *

Message *

Visualforce

Apex

Lightening UI

Translate

Comments