We have enabled platform encryption for managed packages in a developer edition org. We then started encrypting custom fields in our managed package. We expect to receive an error when we try to encrypt a field that is being used to filter a SOQL query. However, one field was encrypted despite being used in a SOQL query in the managed package. Now the class doing the query cannot be compiled because of the following error:

"Error: Compile Error: encrypted field 'xxx__c' cannot be filtered in a query call"

This query was in the package installed in the org when the field was enabled. I have unencrypted the field now but still cannot recompile the class or update the package because of the error. I asked a similar question in a "Pre-Release" org but did not find a solution.

What concerns me is that our customers will be able to encrypt fields and break our package. Any ideas how to prevent or resolve this issue?


2 Answers 2


I'm sorry you're hitting this issue.

When a set of fields are encrypted, we're running various validators to find out whether there are some configurations that prevent some of to those fields from being encrypted.

One validator is about re-compiling all the apex classes and triggers as if those fields were encrypted and catching any compilation error.

Unfortunately, we uncovered recently that if there are multiple errors in the same apex class, only the first one is caught by the apex compiler and another offending field might pass the validations.

As a workaround, if you encrypt your fields one by one, you should not encounter this bug.

But it's not a great answer, we're looking internally at a short term fix if performance permits, the longer term fix is tied to the next generation apex compiler.

For your information, we have a bug that tracks this problem.

  • Thank you so much Alexandre! Greatly appreciate your presence here. Is there any documentation on how the compilation validation works? I have been using Platform Encryption to build a large app and have several questions on this.
    – Jorjani
    Commented Feb 23, 2017 at 19:11
  • I'm sorry there is no precise documentation, but I'm happy to try to answer questions you might have, this could help us improve our validation. Commented Feb 24, 2017 at 17:38
  • see also Deterministic Encryption for resolving equality issues in SOQL WHERE
    – cropredy
    Commented Feb 14, 2018 at 18:57

I also faced this issue. Once one field is encrypted and after that we remove encryption even then we cannot use that field in where clause in soql query.


As said in answer of above link you might have to raise a ticket with salesforce to solve problem.

You must log in to answer this question.

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