We are querying Salesforce using SOQL, if the encryption is enabled for the field that is used in query, we are getting the following error.

Operator like is not supported on an encrypted field

Is there any workaround for this issue?

  • are you using Salesforce Shield Encryption? – Santanu Boral Dec 5 '18 at 11:19
  • Thanks @SantanuBoral for reply . yes i am using the salesforce shield encryption – Karuna Kumar Yatam Dec 5 '18 at 14:11

If you use Deterministic Encryption then LIKE operator is supported.

Deterministic encryption supports WHERE clauses in SOQL queries and is compatible with unique and external ID fields and custom indexes.

For example, you might run a SOQL query in custom Apex code against the Contact object, where LastName = 'Smith'. If the LastName field is encrypted with probabilistic encryption, you can’t run the query. Deterministic encryption addresses this problem.

Refer Encrypt Data with the Deterministic Encryption Scheme

  • 1
    I have enabled Deterministic Encryption and i am trying to execute SOQL query through SOAP API, equals operator is working but not LIKE, Can you please suggest – Karuna Kumar Yatam Dec 5 '18 at 14:13

Operator LIKE is not supported on an encrypted field so you cannot use it, there is not much you can do about that.

What deterministic encryption allows you to do, as opposed to probabilistic, is to use the operator = in a SOQL query since deterministic encryption guarantees that a certain sequence of bits will always be encrypted to the same sequence of bits.

If I were you I would try to change the query that uses the LIKE operator to use = operator. This will also speed up your query significantly.

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.