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
fiona gentryfiona gentry 

How To Implement Full Search in Case Type?

Hi Gurus,
I need to build out a solution to create a search field on the new Case Type Data object in all 3 of the Level fields and populate based on selection.

Similar to SF Global Search I  would like to type 2-3 characters in the text search field and it would find the matching text in the Level1-3 fields and when selected the Level 1-3 field would populate.

What do I need to do to achieve thisUser-added image
Regards,
Fiona
Best Answer chosen by fiona gentry
AnudeepAnudeep (Salesforce Developers) 
Hi Fiona - You need to add another AuraEnabled method in your code and use SOSL as recommended above
 
public class CustomSearchController {
    @AuraEnabled
    public static List<String> searchForIds(String searchText) {
      return new List<String>{searchText};
    }
}
 
public static List<String> searchForIds(String searchText) {
    List<List<SObject>> results = [FIND :searchText IN ALL FIELDS  RETURNING Account(Id), Campaign(Id), Contact(Id), Lead(Id)];
    List<String> ids = new List<String>();
    for (List<SObject> sobjs : results) {
      for (SObject sobj : sobjs) {
        ids.add(sobj.Id);
      }
    }
    return ids;
}

For complete code, refer this documentation

If you find this information helpful, please mark this answer as Best. It may help others in the community

Thanks, 
Anudeep

All Answers

AnudeepAnudeep (Salesforce Developers) 
Hi Fiona - One option is to run a SOQL query like the example described below
 
String sample = '*'+sample+'*';

List<List<Sobject>> = [FIND :sample IN ALL FIELDS RETURNING SOBJECTS_LISt];

I also recommend looking at the sample code in this blog

Let me know if this helps

Thanks, 
Anudeep
fiona gentryfiona gentry
Hi Anudeep,thank you for reply here is the code ,if you can suggest where and what change is needed  to make this search functionality working 

This is the apex class public class PickListHandler {
@AuraEnabled
                    public static List<String> getLevel1(){
                    List<String> tempLst1 = new List<String>();
                        for(AggregateResult  ar : [select Level_1__c,COUNT(id) from Case_Type_Data__c  group by Level_1__c])
                    {
                        tempLst1.add(''+ar.get('Level_1__c'));
                    }

                    return tempLst1;
                      
                      
                    } 
                    
                    @AuraEnabled
                    public static List<String> getLevel2(string strName){
                    List<String> tempLst2 = new List<String>();
                       for(AggregateResult  ar : [select Level_2__c,COUNT(id) from Case_Type_Data__c where Level_1__c=:strName  group by Level_2__c])
                    {
                       tempLst2.add(''+ar.get('Level_2__c'));
                    }

                    return tempLst2;
                      
                    } 
                    
                    @AuraEnabled
                    public static List<String> getLevel3(string strName1,string strName2){
                     List<String> tempLst3 = new List<String>();
                      for(AggregateResult  ar : [select Level_3__c,COUNT(id) from Case_Type_Data__c  where Level_1__c=:strName1 and Level_2__c=:strName2 group by Level_3__c])
                    {
                       tempLst3.add(''+ar.get('Level_3__c'));
                    }

                    return tempLst3;
                      
                      
                    } 
                         
                     @AuraEnabled
                     public  static String  savecasetype(string level1,string level2,string level3,string id){
                     string strMsg='successfull';
                          try{
                     ERT_Case_Type__c obj=new ERT_Case_Type__c();
                     Obj.Case__c = id;
                     System.debug('CASE  = '+ Obj.Case__c); 
                     Obj.Level_1__c=level1;
                     System.debug('Level1  = '+ Obj.Level_1__c); 
                     Obj.Level_2__c=level2;
                     System.debug('Level2  = '+ Obj.Level_2__c); 
                     Obj.Level_3__c=level3;
                     System.debug('Level3  = '+ Obj.Level_3__c); 
                     Insert obj;
                  
                     }
                     
                    catch(Exception ex){
                            strMsg='error';
                        }
                     return strMsg;  
                }
                    
                     
                    
                    

                }


                

This is the Picklist handler component
 
<aura:component controller="PickListHandler" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
                        <!-- Actions-->
                        <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
                        <!-- variable-->
                        <aura:attribute name="lstLevel1" type="String[]" />
                         <aura:attribute name="lstLevel2" type="String[]" />
                          <aura:attribute name="lstL3" type="String[]" />
                        <span> Level 1</span>
                        <ui:inputSelect aura:id="ddLevel1" change="{!c.getLvl1}">
                            <ui:inputSelectOption label="-Select-" value="true"/>        
                            <aura:iteration items="{!v.lstLevel1}" var="value">          
                                <ui:inputSelectOption label="{!value}" text="{!value}" />
                            </aura:iteration>
                        </ui:inputSelect>
                        <span>Level 2</span>
                        <ui:inputSelect aura:id="ddLevel2" change="{!c.getSelectedValue}">
                            <ui:inputSelectOption label="-Select-" value="true"/>        
                            <aura:iteration items="{!v.lstLevel2}" var="value">          
                                <ui:inputSelectOption label="{!value}" text="{!value}" />
                            </aura:iteration>
                        </ui:inputSelect>
                         <span>Level 3</span>
                        <ui:inputSelect aura:id="ddLevel3" >
                            <ui:inputSelectOption label="-Select-" value="true"/>        
                            <aura:iteration items="{!v.lstL3}" var="value">          
                                <ui:inputSelectOption label="{!value}" text="{!value}" />
                            </aura:iteration>
                        </ui:inputSelect>
                       <lightning:button variant="brand" label="Save" onclick="{!c.onConfirm}" />
                    </aura:component>

 
AnudeepAnudeep (Salesforce Developers) 
Hi Fiona - You need to add another AuraEnabled method in your code and use SOSL as recommended above
 
public class CustomSearchController {
    @AuraEnabled
    public static List<String> searchForIds(String searchText) {
      return new List<String>{searchText};
    }
}
 
public static List<String> searchForIds(String searchText) {
    List<List<SObject>> results = [FIND :searchText IN ALL FIELDS  RETURNING Account(Id), Campaign(Id), Contact(Id), Lead(Id)];
    List<String> ids = new List<String>();
    for (List<SObject> sobjs : results) {
      for (SObject sobj : sobjs) {
        ids.add(sobj.Id);
      }
    }
    return ids;
}

For complete code, refer this documentation

If you find this information helpful, please mark this answer as Best. It may help others in the community

Thanks, 
Anudeep
This was selected as the best answer