Skip to main content

Searching Component In SFDC

Hi All,

This is a  cool post for me.Here I have created one page where you can search many sfdc component(apex class,vf pages, user,report,approval process, trigger). 

Useful for Whom ?

  • All developers who always try to finish work as son as possible.
  • Don't want click on Next & Prev link to reach at particular component(if more than 100 is there).
  • Want to get all different component in one page.
  • The best thing is with in less time to get component.

We can search these component as below image.if you want to search more than add that component in options list rest will be take care.




Here is the Page:-

<apex:page controller="SearchApexComponent">
    <apex:form >
        
        <apex:pageBlock title="Find Your SFDC Component" id="pblock">
        <apex:pageMessages id="message"></apex:pageMessages>
         <apex:outputLabel value="Choose Search Item">
                <apex:selectList value="{!objectname}" size="1" multiselect="false">
                    <apex:selectOptions value="{!options }" >
                    </apex:selectOptions>
                </apex:selectList>
            </apex:outputLabel>
            <apex:outputLabel value="Enter Name" for="txt"></apex:outputLabel>
            <apex:inputText value="{!inputString}" id="txt"/>
            <apex:commandButton value="Search" action="{!Showclasses}" reRender="pbt,message,pblock"/>
            <apex:pageBlockTable value="{!Classes}" var="cls" id="pbt">
                <apex:column headerValue=" Name">
                <apex:commandLink action="{!Go}" target="_blank">
                    <apex:param name="clsid" value="{!cls['id']}"/>
                     <apex:outputField value="{!cls['name']}"/> 
                     
                </apex:commandLink>
                </apex:column>
                <apex:column headerValue=" Created By">
                     <apex:outputField value="{!cls['CreatedByid']}"/> 
                </apex:column>
                <apex:column headerValue=" Modified By">
                     <apex:outputField value="{!cls['LastModifiedByid']}"/> 
                </apex:column>
                
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
  
</apex:page>

Here is Controller :-

public with sharing class SearchApexComponent {
    public String inputString{get;set;}
    public String objectname{get;set;}
    public List<sObject> Classes{get;set;}
    string classId;
    public List<SelectOption> options{get;set;}
    public SearchApexComponent(){
        Classes = new List<sObject>();
        options = new List<SelectOption>();
        options.add(new selectOption('','--None--'));
        options.add(new selectOption('ApexClass','ApexClass'));
        options.add(new selectOption('ApexPage','VisualForce Page'));
        options.add(new selectOption('ApexTrigger','Trigger'));
        options.add(new selectOption('Approval','Approval Process'));
        options.add(new selectOption('User','User'));
        options.add(new selectOption('Document','Document'));
        options.add(new selectOption('Profile','Profile'));
        options.add(new selectOption('PermissionSet','PermissionSet'));
        options.add(new selectOption('Report','Report'));
        
    }
    
    public PageReference Showclasses(){
        system.debug('printing claaneem---'+Objectname );
        if(Objectname ==null || Objectname == '' || Objectname == '--None--'){
            
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Please choose component what you want to search');
            ApexPages.addMessage(myMsg);
            return null;   
        }
        else if(inputString ==null || inputString == ''){
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Please Enter Some Input String');
            ApexPages.addMessage(myMsg);
        }
        else{
            String sQuerry  = 'select id,name,CreatedByid,LastModifiedById from '+Objectname +' where name LIKE '+'\'%'+inputString+'%\''+'LIMIT 100';
            System.debug('Print sQuerry  -->'+sQuerry  );
            classes = Database.query(sQuerry );
        }
        
        system.debug('printing Classes list---'+Classes);
        return null;
    }
     
    public PageReference Go(){
        classId = Apexpages.currentpage().getparameters().get('clsid');
        
        PageReference requestPage = new pagereference('https://cs1.salesforce.com/'+classId);
        requestPage.setRedirect(true);
        return requestPage;
    }
}


Comments

There is chrome extension to find apex class, vf page and triggers.Please find below
https://chrome.google.com/webstore/detail/salesforce-advanced-code/lnkgcmpjkkkeffambkllliefdpjdklmi

Popular posts from this blog

Style in LWC

 Following are the ways we can apply in CSS in LWC. 1. Inline CCS Inline CSS is not recommended approaches, it is take highest priority among all CSS. style="color:green;font-size:10px;" is inline CSS added to div < template >     < lightning-card title = "Inline CSS" >         < div >             < div style = "color:green;font-size:10px;" > This is inline Style div </ div >         </ div >     </ lightning-card > </ template >  2. External CSS style can be applied to an elements such as h1, p,div span etc. It can applied to class using "." notation. for example .user{} It can also be applied to pseudo class.  for example .user:hover{} Id locator is not being used in LWC to apply style To apply external css, need to create separate CSS file, file name should be exactly matched with component name. for example - If component name is ...

How to Create/Delete file attachments(Content Document) through Apex ?

 There are 3 standard salesforce objects to store file attachments. Content Document, ContentDocumentVersion, ContentDocumentLink.  Here is the article to talk about these objects and relationship.  https://www.forcetalks.com/blog/contentdocument-and-contentversion-in-salesforce-an-overview/ ContentDocumentVersion ContentDocumentLink This post is all about how to create/delete content document though Apex. Here is code snippet // Insert Content Version record ContentVersion contentVersionRec = new ContentVersion(Title='filename',PathOnClient ='FileName.pdf',VersionData = bodyBlob,origin = 'H'); INSERT contentVersionRec; // this will insert one record in ContentDocument and ContentVersion , ContentDocument  is parent and  ContentVersion is child record // get contentdocument id contentVersionRec = [SELECT Id, Title, ContentDocumentId FROM ContentVersion WHERE Id = :contentVersionRec .Id LIMIT 1]; // Create Content Document Link record- This will attach ...

Lifecycle hooks in LWC

There are 3 phase of LWC component  1. Mounting  A. constructor, B. connnectedCallback C. render D. renderedCallback 2. UnMounting  A. disconnectedcallback 3. Error  A.errorcallback Note - render is not lifecycle hook, it is protected method of Lightning element class. Mounting Phase LWC Creation and Render Life cycle Constructor Method ·        This method called when component is instantiated and It flows from parent to child component. ·        Need to call Super() inside constructor method ·        Can’t access any component properties or child component because it’s not ready yet. ·        Host element can be accessed through “this. template” inside constructor method. ·        Don’t add any attributes to host inside constructor C   constructor (){          super (); //...