You need to sign in to do that
Don't have an account?
Rakesh E
How to search in specific fields using SOSL queries
Hi,
I want to use SOSL for searching a value in some(specific) fields rather than in ALL fileds.
i have observed that only dataType can be mentioned there like Phone Fields or Email fields .
please let me know if there is any possibility to search in specific fileds.
thanks in advance
No, you can't search in specific fields. If you need to find text that appears in specific fields, you should use a SOQL query where you can identify the specific field and search string(s).
The only way to achieve this in SOSL would be to execute the search and then post-process the results to filter out those with fields that don't contain the search query.
oh thank you for your reply.
i wanted to explain my scenario here.
i am displaying a set of fields to the user and when user enters any search value , that has to be serached only in the fields which we are displaying.
and one more doubt , can we use OFFSET in SOSL queries (we have pagination)
Thanks
Regards
Rakesh
This sounds like a use case for SOQL - you can dyamically build the query to check the fields that you have displayed.
No, you can't use pagination in SOSL - it returns a maximum of 200 results.
Can you please advice.
I have similar requirement wherein have salesforce site where the VF page displays some Contact fields(totally on contact object and it's fields). On that user can search for Name ,Title ,Company fields. This is all done with SOQL.
Now we have encrypted(shield platform encryption) all this fields and hence I have to convert this SOQL to SOSL as filters are not supported on encrypted fields. Also I have Pagination on that VF page.
I have modified the SOQL to SOSL something like below:
if(String.isNotEmpty(searchContactsName) || String.isNotEmpty(searchContactsTitle) || String.isNotEmpty(searchContactsOrg) ) {
showTheCount = true;
if(String.isNotEmpty(searchContactsName)) {
strSearch =+ '("' + searchContactsName + '")';
strConcat = true;
}
if(!String.isEmpty(searchContactsTitle)){
if(!String.isEmpty(strSearch )){
strSearch =+ ' OR ';
}
strSearch =+ '("' + searchContactsTitle + '")';
strConcat = true;
}
if(!String.isEmpty(searchContactsOrg)){
if(!String.isEmpty(strSearch )){
strSearch =+ ' OR ';
}
strSearch =+ '("' + searchContactsOrg + '")';
strConcat = true;
}
String searchQuery = 'FIND \'' + String.escapeSingleQuotes(strSearch)+ '\' IN ALL FIELDS RETURNING Contact(Name,Title )';
List<List<sObject>> searchConLead = search.query(searchQuery);
However am getting error like --------- line 1:178 no viable alternative at character '"'.
Can you please advice here how can I achive this.