[SalesForce] How to write SOSL IN query

I've following SOQL query –

SELECT Id, Name, Email, Account.Id, Account.Name FROM Contact WHERE Email in :emails

Here emails is a comma separated list of email ids.

Can I write the same query in SOSL? I'll be running the query using rest API. The reason I want to do it using SOSL is –

a) I want to get around the limit of 4000 characters in SOQL where clause

b) I also want to search Lead object, not just Contact. This one is low priority though.

Best Answer

Yes, you can write the query in SOSL. There's a great bit of info here: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl.htm

Please be aware that SOSL isn't the most precise way of finding records, so you may be better off even splitting your query into two SOQL queries and combining the result objects somehow.

I'm a little nervous that you might have a SOQL query of longer than 4000 characters. Do you really need every part of it? All the fields and all the WHERE clause parts? If so, you may wish to consider breaking your query into multiple queries and combining them.

Related Topic