List<user> users = [SELECT Id,name FROM User WHERE (FirstName != Lastname)];このクエリを実行すると "System.QueryException: unexpected token: 'Lastname' " (予期しないトークン) が返されます。
Salesforce では、SOQL クエリで項目間の直接比較はできません。
項目を比較して (true や false などの) 値を返す式項目を作成して WHERE 句で使用すると、これを実現できます。
上記のクエリの場合、テキスト型の値を返す式項目 (例: NameCompare) を次の式で User オブジェクトに作成できます。
IF(User.FirstName != User.LastName, 'true', 'false')
クエリは次のようになります。
List<User> Users = [SELECT id, name FROM User where NameCompare = 'true'];
レポートでこれを実行できるようになりました。この機能は Spring '20 リリースで実装されました。
参照: 項目間の検索条件を使用した項目の比較によるレポートの絞り込み
IdeaExchange の Field-to-Field filters for SOQL へ投票とコメントをしてください。
000386076

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.