I tried to run this query and got the error as 'name' can not be filtered in a query call. The query is [select id,name from contact where name like '%test%'] . The result is varying from org to org. I tried in my developer edition and it is working fine. when I try this is in my project sandbox and I got the mentioned error.
-
Is Name field encrypted in your project sandbox. Like are you using Salesforce Shield implementation?– SaiPraveen KakkiralaMar 24, 2022 at 6:43
-
how do I know that field is encrypted. because when I use soql as plain like [select id,name from contact where firstname != null] . it is working totally fine. but I cannot use the like operator– prasanthMar 24, 2022 at 6:45
2 Answers
As mentioned in my comment the encryption fields cannot be used in the filter criteria . You cannot use those field in Aggregate functions such as MAX(), MIN(), and COUNT_DISTINCT(),WHERE clause,GROUP BY clause,ORDER BY clause as well.
You may have to remove the encryption to use them in the above scenarios. Please find the below article from Salesforce which explains the same .
-
-
1There was a tip in the above article saying to Consider whether you can replace a WHERE clause in a SOQL query with a FIND query in SOSL. Mar 24, 2022 at 8:11
I came to know that the field is encrypted and I removed the encryption for contact name field and the query is working now.