I am trying to enable platform encryption for the 'Email' field but I have used this field in my SOQL where clause. So, while enabling I am getting error as below:

Apex Class: SaveCaseRestAPI, line 31, column 32: field 'Email' can not be filtered in a query call

Kindly help me how could I enable this field for Encryption.

  • which kind of encryption you have enabled. There are certain limitation with each algorithm
    – Ysr Shk
    Commented Nov 9, 2020 at 10:05

1 Answer 1


If you want to encrypt a field and still use it in a query you need to change the way you query the data. Our general approach, certainly for User and Contact email addresses, was to:

  1. Switch from SOQL to SOSL, having the SOSL search for the required value in the "EMAIL FIELDS" search group using the match value for the SearchQuery.
  2. Post-filter the returned data to ensure we actually have the appropriate records returned (the search group may cause unexpected records to be returned because it can match against multiple fields and SOSL doesn't give you the fine control for this).

Fundamentally once you encrypt a field you cannot use it in WHERE or ORDER BY clauses in SOSL or SOQL. Check the documentation for more details.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .