+ Start a Discussion
Briana L.Briana L. 

SOSL for Encrypted Field returns no results

I am trying to write a SOSL query to find a match on a custom Social Security Number Field. According to the documentation, SOSL should be able to return results for encrypted fields, but the results returned are blank.

My user has "View Encrypted Data" permission.
We are managing a package, but the code includes the namespace.

This SOSL returns 0 rows, and an empty list, even though I KNOW that there are records with '1111' in the social security number custom field because I created them for testing.
List<List<sObject>> results = [FIND '1111' IN 
                               ALL Fields RETURNING 
                               aescsep__SCSEP_Participant__c(id, name, aescsep__social_security_number__c)];
system.debug(results[0]);
I know that the syntax of the SOSL is correct because if a replace the '1111' keyword with something like 'test' I am able to return records that have 'test' in non-encrypted fields.

Can someone please provide a solution that will return matching participants by encrypted SSN?
Raj VakatiRaj Vakati

For the record, text(Encrypted) is not the same as text, hence, not queryable with SOSL.
When Using Shield Platform Encryption, There are certain considerations when using SOSL and SOQL:

https://help.salesforce.com/articleView?id=security_pe_considerations_general.htm&type=0
https://help.salesforce.com/articleView?id=search_fields_contact.htm&type=5
https://salesforce.stackexchange.com/questions/201007/using-encrypted-fields-in-sosl-query-gives-in-0-results
Briana L.Briana L.
Hi Raj,

Yes I understand that text(Encrypted) is not the same as text.
However, this resource: https://developer.salesforce.com/page/ISVPlatformEncryption#Key_limitations_and_their_workarounds indicates that you can use SOSL to query for encrypted fields, and I followed the example exactly but it is not working.
Raj VakatiRaj Vakati
It seems to be confusing for me also .. i tried same in my instance but no data is returned