You need to sign in to do that
Don't have an account?
Kolli
Dynamic SOSL with multiple search terms not returning records with email or phone number
I am facing couple of challenges with Dynamic SOSL.
Records are available with "test.abc1@test.digital or test.abc@test.com" and "(123) 456-7890"(based on locale).
we are using Dynamic SOSL query with multiple search terms and asterisk match (*)
Email field not working with :-
1)searchTerm ="@test.digital*"
2)searchTerm ="abc1*"
3)searchTerm ="abc1@test.digital*" or searchTerm =".abc1@test.digital*"
Phone number not working with :-
1)searchTerm ="890*"
2)searchTerm ="23)4*"
3)searchTerm ="67890*"
***We ant fetch records with any character from email field and any number from Phone number field.***
we tried multiple ways suggested by salesforce i.e.
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_find.htm
Code :-
SearchCaseByMultipleId(string searchText){
String searchTerms = '(';
for(string str : searchText.split(',')){
if(str.length()>0){
searchTerms = searchTerms+' "' +str +'*'+'" '+'OR';
}else{
}
}
searchTerms = searchTerms.removeEnd('OR');
searchTerms = searchTerms+')';
string finalQuery = 'FIND :searchTerms IN ALL FIELDS RETURNING '+objectName+'(' + quryFields +'
ORDER BY CreatedDate DESC NULLS last)';
list<list<Sobject>> results = search.query(finalQuery);
}
search term looks like :- ("@test.digital*" OR "abc1*").
is there any other way for my requirement or is something missing?
Records are available with "test.abc1@test.digital or test.abc@test.com" and "(123) 456-7890"(based on locale).
we are using Dynamic SOSL query with multiple search terms and asterisk match (*)
Email field not working with :-
1)searchTerm ="@test.digital*"
2)searchTerm ="abc1*"
3)searchTerm ="abc1@test.digital*" or searchTerm =".abc1@test.digital*"
Phone number not working with :-
1)searchTerm ="890*"
2)searchTerm ="23)4*"
3)searchTerm ="67890*"
***We ant fetch records with any character from email field and any number from Phone number field.***
we tried multiple ways suggested by salesforce i.e.
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_find.htm
Code :-
SearchCaseByMultipleId(string searchText){
String searchTerms = '(';
for(string str : searchText.split(',')){
if(str.length()>0){
searchTerms = searchTerms+' "' +str +'*'+'" '+'OR';
}else{
}
}
searchTerms = searchTerms.removeEnd('OR');
searchTerms = searchTerms+')';
string finalQuery = 'FIND :searchTerms IN ALL FIELDS RETURNING '+objectName+'(' + quryFields +'
ORDER BY CreatedDate DESC NULLS last)';
list<list<Sobject>> results = search.query(finalQuery);
}
search term looks like :- ("@test.digital*" OR "abc1*").
is there any other way for my requirement or is something missing?
Greetings!
You need to include the field names based on the Object for example:
I would suggest you to first try by using the direct values and then try with the binding variable.
Kindly mark it as best answer if it helps so that it can help others in the future.
Warm Regards,
Shirisha Pathuri
Thanks for reply.
Fields are included in the dynamic query with variable of "queryfields".
Also we tried in both ways direct values and binded values but not getting the records.