3

Currently I am using SOQL query in apex class:

for(Account acc: [Select FirstName,LastName,Territory_vod__c,NPI_vod__c from Account where Name In:accountSet ]){

accountSet is set having list of names. Due to requirements,I need to replace this query with SOSL query with something like this:

FIND :accountSet IN NAME FIELDS Returning account(id)

but I am not able to iterate over accountSet. What could be the workarounds to use set in SOSL query.

2

You need to use parenthesis for search in your SOSL. Refer FIND {SearchQuery} document.

Quote from documentation:

( )- Use parentheses around search terms with logical operators to group search terms. For example, you can search for: ("Bob" and "Jones") OR ("Sally" and "Smith")—searches for either Bob Jones or Sally Smith. ("Bob") and ("Jones" OR "Thomas") and Sally Smith—searches for documents that contain Bob Jones and Sally Smith or Bob Thomas and Sally Smith.

An example here:

String searchTerms = '("keyWord 1") OR ("keyWord 2")';
System.debug([FIND :searchTerms RETURNING Account(Name, Rating, BillingState)]);

So, You have to enclose each tearm inside a parenthesis and use AND/OR operator.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.