Assume, I’ve got a standard picklist field
Rating
onAccount
with valuesHot
,Cold
. Using enabledTranslation Workbench
I’ve translated these values into German.
When the language of a user is set toEnglish
, and the user performs a SOQL querySELECT Id, Rating FROM Account WHERE Rating LIKE 'Cold'
it returns
N
records. But if we change the language of the user toGerman
, the same SOQL query returns0
records. However, when it changes toSELECT Id, Rating FROM Account WHERE Rating LIKE 'Kalt'
it returns
N
records as well as for the very first scenario. At the same time, the returned values of theRating
field remain untranslated (‘Cold’). This means that theLIKE
operator implicitly translates the values of picklists before comparison. I’ve testedIN
,NOT IN
,=
SOQL Comparison Operators and they don’t behave likeLIKE
, they perform a comparison based on picklist valueAPI Name
notLabel
. There is no such information about it in Salesforce Docs.
So finally my question is:Why does the
LIKE
SOQL operator implicitly translate picklist values before comparison and how to perform a comparison based on picklist value API Names using theLIKE
operator?
Answer
This is what I thought was the reason for the LIKE
operator to automatically translate picklist values, and that has been confirmed on the documentation since Spring ’21: The LIKE
operator is used to match strings. The picklist value is translated, probably because of situations when the end-user searches for text in his own language.
Consider the following situation: a custom search component for a multinational company that supports many languages. The requirement is to enable search in picklist values that are being added/deactivated every month or so. If the user wants to search for a string, he won’t type the API name of the field, but the translated version of the value he wants to get.
Attribution
Source : Link , Question Author : Oleh Berehovskyi , Answer Author : Renato Oliveira