如何使用Salesforce在案例类型中实施完全搜索? [英] How To Implement Full Search in Case Type using Salesforce?

查看:78
本文介绍了如何使用Salesforce在案例类型中实施完全搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要构建一个解决方案,以在所有级别"字段的所有3个新案例类型数据"对象上创建一个搜索字段,然后根据选择进行填充.

类似于SF Global Search,我想在文本搜索字段中键入2-3个字符,它会在Level1-3字段中找到匹配的文本,并且在选中后将填充1-3级字段.

这是顶点类

 公共类PickListHandler {@AuraEnabled公共静态List< String>getLevel1(){List< String>tempLst1 = new List< String>();对于(AggregateResult ar:[按Level_1__c从Case_Type_Data__c组中选择Level_1__c,COUNT(id)]){tempLst1.add(''+ ar.get('Level_1__c'));;}返回tempLst1;}@AuraEnabled公共静态List< String>getLevel2(字符串strName){List< String>tempLst2 = new List< String>();for(AggregateResult ar:[从Case_Type_Data__c中选择Level_2__c,COUNT(id),其中Level_1__c =:strName按Level_2__c分组)]{tempLst2.add(''+ ar.get('Level_2__c'));;}返回tempLst2;}@AuraEnabled公共静态List< String>getLevel3(字符串strName1,字符串strName2){List< String>tempLst3 = new List< String>();for(AggregateResult ar:[从Case_Type_Data__c中选择Level_3__c,COUNT(id),其中Level_1__c =:strName1和Level_2__c =:strName2按Level_3__c组]]{tempLst3.add(''+ ar.get('Level_3__c'));;}返回tempLst3;}@AuraEnabled公共静态字符串savecasetype(字符串级别1,字符串级别2,字符串级别3,字符串ID){字符串strMsg ='successfull';尝试{ERT_Case_Type__c obj =新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);插入obj;}catch(特例例外){strMsg ='错误';}返回strMsg;}} 

这是Picklist处理程序组件

 < aura:component controller ="PickListHandler";实现="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction".访问=全局"><!-动作->< aura:handler name =" init"value =" {!this}"action ="{!c.doInit}"/><!-变量->< aura:attribute name ="lstLevel1"type =" String []";/>< aura:属性名称="lstLevel2";type =" String []";/>< aura:属性名称="lstL3";type =" String []";/>< span>级别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>级别2</span>< ui:inputSelect aura:id =" ddLevel2"更改="{!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>级别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><闪电:按钮变体=品牌";标签=保存"onclick ="{!c.onConfirm}"/></aura:component> 

关于,卡罗琳

解决方案

您需要很多东西,我们没有您的自定义对象.这是旧代码,

顶点类

 具有共享类Stack64129038的公共{@AuraEnabled(cacheable = true)公共静态List< LookupSearchResult>search(String searchTerm,List< String> selectedIds){if(String.isBlank(searchTerm)|| searchTerm.length()< 2){返回null;}字符串t ='%'+ searchTerm +'%';//决定您要如何搜索,以...开头",包含"还是什么列表< Case_Type_Data__c>记录= [SELECT ID,名称,Level_1__c,Level_2__c,Level_3__c从Case_Type_Data__c其中Level_1__c LIKE:t或Level_2__c LIKE:t或Level_3__c LIKE:t按Level_1__c,Level_2__c,Level_3__c排序LIMIT 20];/*您还可以尝试SOSL?记录= [查找:('*'+ searchTerm +'*')在所有字段中返回Case_Type_Data__c(Id,Name,Level_1__c,Level_2__c,Level_3__c)] [0];*/列表< LookupSearchResult>结果=新的List< LookupSearchResult>();for(Case_Type_Data__c ctd:记录){results.add(new LookupSearchResult(ctd.Id,'Case_Type_Data__c','standard:case_wrap_up',ctd.Name,String.join(新列表< String> {ctd.Level_1__c,ctd.Level_2__c,ctd.Level_3__c},';')));}返回结果;}} 

光环组件(HTML部分)

 < aura:component Implements =" force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes,force:lightningQuickAction访问=全局"控制器="Stack64129038".< aura:attribute access ="private"type ="List"名称=选择"默认值="[]"/>< aura:attribute access ="private"type ="List"名称=错误"默认值="[]"/>< lightning:card title ="New Case Type">< lightning:recordEditForm aura:id =" myForm"objectApiName ="ERT_Case_Type__c";onsubmit =" {!c.onSubmit}"onsuccess ="{!c.onSuccess}">< lightning:messages/>< c:查找选择=" {!v.selection}"onSearch =" {!c.lookupSearch}"onSelection =" {!c.useSelected}"errors ="{!v.errors}"label =搜索"占位符=搜索用例类型数据"/< lightning:inputField aura:id =" Level_1__c"fieldName =" Level_1__c"/>< lightning:inputField aura:id =" Level_2__c"fieldName ="Level_2__c";/>< lightning:inputField aura:id =" Level_3__c"fieldName ="Level_3__c";/>< lightning:button class =“ slds-m-top_small"变体=品牌".type ="submit"name =保存"标签=保存"/></lightning:recordEditForm></lightning:card></aura:component> 

Aura组件-JS控制器部分

 ({lookupSearch:函数(组件,事件,帮助器){//获取触发搜索事件的查找组件const lookupComponent = event.getSource();const serverSearchAction = component.get('c.search');lookupComponent.search(serverSearchAction);},useSelected:function(component,event,helper){const selection = component.get('v.selection');const错误= component.get('v.errors');如果(selection.length){if(errors.length){//清除错误(如果有)component.set('v.errors',[]);}让级别= selection [0] .subtitle.split(';');component.find('Level_1__c').set('v.value',levels [0]);component.find('Level_2__c').set('v.value',levels [1]);component.find('Level_3__c').set('v.value',level [2]);}},onSubmit:函数(组件,事件,助手){调试器;event.preventDefault();//停止提交表单var fields = event.getParam('fields');fields.Case__c = component.get('v.recordId');//链接到"this"案件component.find('myForm').submit(fields);},onSuccess:功能(组件,事件,助手){var toastEvent = $ A.get("e.force:sh​​owToast");toastEvent.setParams({标题":成功!","message":案例类型已保存,确定,正在刷新",类型":成功"});toastEvent.fire();$ A.get('e.force:refreshView').fire();//重新加载页面}}) 

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.

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>

Regards, Carolyn

解决方案

You're asking for a lot, we wouldn't have your custom object. And this is old code, ui:inputSelect is deprecated for 1 year now. I'll try to help a bit but the whole thing needs your work too. And examples we can reproduce easily.

I'm going to cheat and use Philippe Ozil's ready component for the lookup/autocomplete thing. It means you'd have to save LookupSearchResult class, the whole aura component and 2 aura events in your org before reading below. That's some prep work but it's battle-tested :)

Apex class

public with sharing class Stack64129038 {
    @AuraEnabled(cacheable=true)
    public static List<LookupSearchResult> search(String searchTerm, List<String> selectedIds){
        if(String.isBlank(searchTerm) || searchTerm.length() < 2){
            return null;
        }
        String t = '%' + searchTerm + '%'; // decide how you want to search, "starts with", "includes" or what
        
        List<Case_Type_Data__c> records = [SELECT Id, Name, Level_1__c, Level_2__c, Level_3__c
            FROM Case_Type_Data__c
            WHERE Level_1__c LIKE :t OR Level_2__c LIKE :t OR Level_3__c LIKE :t
            ORDER BY Level_1__c, Level_2__c, Level_3__c
            LIMIT 20];
        
        /* You could also experiment with SOSL?
        records =  [FIND :('*' + searchTerm + '*') IN ALL FIELDS 
            RETURNING Case_Type_Data__c(Id, Name, Level_1__c, Level_2__c, Level_3__c)][0];
        */
        
        List<LookupSearchResult> results = new List<LookupSearchResult>();
        for(Case_Type_Data__c ctd : records){
            results.add(new LookupSearchResult(ctd.Id, 'Case_Type_Data__c', 'standard:case_wrap_up', ctd.Name,
                String.join(new List<String>{ctd.Level_1__c , ctd.Level_2__c, ctd.Level_3__c}, '; ')
            ));
        }
        return results;
    } 
}

Aura component (html part)

<aura:component implements="force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="Stack64129038">
    <aura:attribute access="private" type="List" name="selection" default="[]"/>
    <aura:attribute access="private" type="List" name="errors" default="[]"/>

    <lightning:card title="New Case Type">
        
        <lightning:recordEditForm aura:id="myForm" objectApiName="ERT_Case_Type__c" onsubmit="{!c.onSubmit}" onsuccess="{!c.onSuccess}">
        <lightning:messages />
        <c:Lookup selection="{!v.selection}" onSearch="{!c.lookupSearch}" onSelection="{!c.useSelected}" errors="{!v.errors}" label="Search" placeholder="Search Case Types Data"/>
        <lightning:inputField aura:id="Level_1__c" fieldName="Level_1__c" />
        <lightning:inputField aura:id="Level_2__c" fieldName="Level_2__c" />
        <lightning:inputField aura:id="Level_3__c" fieldName="Level_3__c" />
        <lightning:button class="slds-m-top_small" variant="brand" type="submit" name="save" label="Save" />
    </lightning:recordEditForm>
    </lightning:card>
</aura:component>

Aura component - JS controller part

({
    lookupSearch : function(component, event, helper) {
        // Get the lookup component that fired the search event
        const lookupComponent = event.getSource();
        const serverSearchAction = component.get('c.search');
        lookupComponent.search(serverSearchAction);
    },

    useSelected: function(component, event, helper) {
        const selection = component.get('v.selection');
        const errors = component.get('v.errors');
        
        if (selection.length) {
            if(errors.length){  // Clear errors, if any
                component.set('v.errors', []);
            }
            let levels = selection[0].subtitle.split('; ');
            component.find('Level_1__c').set('v.value', levels[0]);
            component.find('Level_2__c').set('v.value', levels[1]);
            component.find('Level_3__c').set('v.value', levels[2]);
        }
    },
    onSubmit: function(component, event, helper) {
        debugger;
        event.preventDefault();       // stop the form from submitting
        var fields = event.getParam('fields');
        fields.Case__c = component.get('v.recordId'); // link to "this" Case
        component.find('myForm').submit(fields);
    },
    onSuccess: function(component, event, helper){
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            "title": "Success!",
            "message": "Case Type saved OK, refreshing",
            "type": "success"
        });
        toastEvent.fire();
        $A.get('e.force:refreshView').fire(); // reload page
    }
})

这篇关于如何使用Salesforce在案例类型中实施完全搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆