You need to sign in to do that
Don't have an account?
Nilesh Jagtap (NJ)
Dynamic SOSL with hyphen in search string
Hi,
I am trying to perform dynamic search with sosl but gettig 0 rows.
For same query it is returning 4 rows on workbench.
here is the code snippet for refernce:
Thanks,
N.J
I am trying to perform dynamic search with sosl but gettig 0 rows.
For same query it is returning 4 rows on workbench.
here is the code snippet for refernce:
list<String>lstNames = new list<String>{'Brain-Prick@gmail.com','Dorsy.Young@coe.com', 'nj-sf@dev.com'}; String searchquery='FIND {'+ getNames(lstNames) +'} IN ALL FIELDS RETURNING Account(Id,Name),Contact(Id,Name), Lead(Id, Name)'; public string getNames(list<string> lstNames){ String nameList =''; for(String name:lstNames){ //escape hyphen if(name.indexof('-')>=0){ name = name.replace('-', '\\-'); } nameList = nameList + name + ' OR '; } nameList = nameList.substringBeforeLast('OR').trim(); return nameList; }
Thanks,
N.J
Change name = name.replace('-', '\\-'); to name = name.split('-')[0]+'*';
Thanks
Did you get the answer?