I am experiencing some unexpected results when querying a on a text field that is using Case Sensitive Deterministic Encryption.
The field can contain dashes -
in the string, when I use an exact match in WHERE CLAUSE of a SOQL query no results are returned
Example (Imagine I have two Account records, and each have custom fields with values as follows):
Account.Encrypted_Field__c = 123-45-6789
Account.Encrypted_Field__c = 123456789
SELECT Encrypted_Field__c FROM Account WHERE Encrypted_Field__c = '123456789'
Returns 1 row.
SELECT Encrypted_Field__c FROM Account WHERE Encrypted_Field__c = '123-45-6789'
Returns 0 rows.
Example Code:
List<Account> acc = [SELECT Id,Encrypted_Field__c FROM Account where id = '...'];
acc[0].Encrypted_Field__c = '862-52-1771';
update acc[0];
acc.clear();
acc = [SELECT Id,Encrypted_Field__c FROM Account where Encrypted_Field__c = '862-52-1771'];
System.assertEquals(1, acc.size());
Fails. No results returned.
But the following does work (SOSL):
List<Account> acc = [SELECT Id,SSN__c FROM Account where id = '...'];
acc[0].Encrypted_Field__c = '862-52-1771';
update acc[0];
List<List<sObject>> accounts = [FIND '862-52-1771' IN ALL FIELDS Returning Account ];
System.assertEquals(1, accounts[0].size());
The documentation of limitations mentions that I need to 'exact' filters on the SOQL queries, but doesn't mention anything about "special characters" (that I've found so far.
As a test I created another text field the same length ( but not encrypted ) and ran the following code which passed:
List<Account> acc = [SELECT Id,Encrypted_Field_Test__c FROM Account where id = '...'];
acc[0].Encrypted_Field_Test__c = '862-52-1771';
update acc[0];
acc.clear();
acc = [SELECT Id,Encrypted_Field_Test__c FROM Account where Encrypted_Field_Test__c = '862-52-1771'];
System.assertEquals(1, acc.size());