0

Due to the need to apply Platform Encryption to the email address field on Contact and the fact that you can't use encrypted fields in a SOQL WHERE clause, I'm trying to convert the query to a SOSL search.

Are these two snippets functionally equivalent? Doesn't feel like they are but not sure what the FIND clause should contain for SOSL

SOQL

for (Contact c : [Select Id, User__c, email, AccountId 
                            from Contact 
                            where (RecordTypeId = : EmployeeRecordTypeId
                                    and User__c in : newUserMap.keyset())
                            or (User__c = null
                                    and email in : userEmails)])

SOSL

for (Contact c : [FIND {:userEmails} IN ALL FIELDS
                            RETURNING Contact(Id,User__c,Email,AccountId
                            WHERE (RecordTypeId = :EmployeeRecordTypeId
                            AND User__c IN :: newUserMap.keyset())
                            OR User__c = null)])
2

The SOSL and SOQL query which you have written are not equivalent. SOSL query always returns List> although you are querying only for Contact object.

Also, the search string which you have given is List and it should be only of only String type.

You can modify the search term using this link: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_find.htm

More info about SOSL: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl.htm

Let me know it helps.

0

No SOSL results are not predictable.

Here is the explanation for SOSL behaviour :

What are the main limits in relation to SOSL?

The record data in Salesforce is stored and indexed in partitions. Records for the same entity can be stored across several partitions. Salesforce searches across up to a maximum of 50k records per partition and can collect up to a maximum of 10k records per entity per partition. After searching all partitions, the maximum results the can be returned per entity is 2,000.

What is SOSL truncation?

Truncation is the process of the search of partitions is completed. After the SOSL completes the scanning of all partitions (with whatever limit is being used), we then apply sharing and any "WHERE" clauses to the returned rows. This can result in eliminating all returned rows and a possibility of returning 0 records to the end user.

for more details refer here

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.