3

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?

2
  • are you using Salesforce Shield Encryption? Dec 5, 2018 at 11:19
  • Thanks @SantanuBoral for reply . yes i am using the salesforce shield encryption Dec 5, 2018 at 14:11

2 Answers 2

2

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.

1
  • SOSL can also be used with encrypted fields to get inexact matches.
    – Shanerk
    Apr 15, 2021 at 16:44
0

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

2
  • 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 Dec 5, 2018 at 14:13
  • Incorrect per the docs: SOQL LIKE and STARTS WITH Statements Deterministic encryption only supports exact, case-sensitive matches. Comparison operators that return partial matches aren’t supported. For example, LIKE and STARTS WITH statements aren’t supported. developer.salesforce.com/docs/…
    – Shanerk
    Apr 15, 2021 at 16:43

You must log in to answer this question.

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