From 771bf9cee05fc409792a93f6cd57acdad3160286 Mon Sep 17 00:00:00 2001 From: Mohammed Wasef Mohiuddin Date: Sun, 12 May 2024 19:17:09 -0400 Subject: [PATCH] Update SearchController.cls - SOSL Fix Since SOSL has a minimum limit, included this for the first couple characters, as it was giving errors and throwing exceptions --- .../customLookup/classes/SearchController.cls | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/sfdxsrc/customLookup/classes/SearchController.cls b/sfdxsrc/customLookup/classes/SearchController.cls index d57748a..aa2c930 100644 --- a/sfdxsrc/customLookup/classes/SearchController.cls +++ b/sfdxsrc/customLookup/classes/SearchController.cls @@ -1,9 +1,9 @@ /** - * @description : + * @description : * @author : Amit Singh - * @group : - * @last modified on : 12-21-2021 - * @last modified by : Amit Singh + * @group : + * @last modified on : 05-12-2024 + * @last modified by : Wasef Mohiuddin **/ public with sharing class SearchController { @AuraEnabled @@ -18,7 +18,14 @@ public with sharing class SearchController { String soqlQuery = 'SELECT Id, Name, Type, LastViewedDate FROM RecentlyViewed WHERE Type =\''+objectName+'\' ORDER BY LastViewedDate DESC LIMIT 5'; sobjList = Database.query( soqlQuery ); searchRecords.add(sobjList); - }else{ + } + //Since SOSL has a minimum limit, included this for the first couple characters, as it was giving errors + else if(searchTerm.length()<3){ + String soqlQuery = 'SELECT Id, '+String.join(fields,',')+' FROM '+objectName+' WHERE Name LIKE \'%'+searchTerm+'%\' LIMIT 5'; + sobjList = Database.query( soqlQuery ); + searchRecords.add(sobjList); + } + else{ searchRecords = Search.Query(Query); } return searchRecords.get(0); @@ -36,4 +43,4 @@ public with sharing class SearchController { } return createdRecord; } -} \ No newline at end of file +}